Domanda

I'm getting the following error after following and adapting this

ParameterNotFoundException: You have requested a non-existent parameter "mynamespace_admin.amazon_s3.aws_key". Did you mean this: "mynamespace_admin.amazon_s3.class"?

In config.yml I have:

mynamespace_admin:
     amazon_s3:
         aws_key:        %amazon_aws_key%
         aws_secret_key: %amazon_aws_secret_key%
         base_url:       %amazon_s3_base_url%

And in my parameters.yml I have:

amazon_aws_key:         ###
amazon_aws_secret_key:  ###
amazon_s3_base_url:     ###
amazon_s3_bucket_name:  ###

And in services.yml:

parameters:
     mynamespace_admin.amazon_s3.class: AmazonS3
     mynamespace_admin.image_uploader.class: mynamespace\Bundle\AdminBundle\Uploader\ImageUploader

    mynamespace_admin:
          amazon_s3:
            class: %mynamespace_admin.amazon_s3.class%
            arguments:
              - "%mynamespace_admin.amazon_s3.aws_key%"
              - "%mynamespace_admin.amazon_s3.aws_secret_key%"

          image_uploader:
            class: mynamespace_admin.image_uploader.class%
            arguments: [image_storage_filesystem]

Can anyone see what I have configured incorrectly or advise on how to debug this? Why can't mynamespace_admin.amazon_s3.aws_key be read from config.yml?

È stato utile?

Soluzione

If things are not listed under the parameters key in the service configuration, it is not assumed it is a parameter.

In all other cases (except from the services key), it is assumed that it is the configuration for an extension. In this case, the extension called mynamespace_admin. That extension should parse the settings and maybe put them in the container as parameters, or use them to decide which files to include, etc.

Assume you have a correct Configuration class for the config you have given, your extension will look like this if you want to use the config as parameters:

// ...
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

class MynamespaceAdminExtension extends Extension
{
    /**
    * {@inheritDoc}
    */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        // ... do some other stuff, like loading service definition files

        // loop through the processed config and save them as parameters
        foreach ($config['amazon_s3'] as $name => $value) {
            $container->setParameter('mynamespace_admin.amazon_s3.'.$name, $value);
        }
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top