user6827096
user6827096

Reputation: 1394

How to retrieve parameter from parameters.yml outside controller?

I need parameter from parameters.yml in Command\ContainerAwareCommand class. I don't see $this->getParameter() there.

Is there a simple way to retrieve parameter from parameters.yml outside controller?

Simpler than: Write "friendly configuration", and put parameter foo into config.yml, and then retrieve param in DependencyInjection\Extension::load(), and set it: $container->setParameter('foo', $foo), and finally in Command\ContainerAwareCommand retrieve it $this->getContainer()->getParameter('foo')?

Upvotes: 2

Views: 1440

Answers (1)

Matteo
Matteo

Reputation: 39370

You can simply access to the container via:

... extends ContainerAwareCommand

...
$this->getContainer()->getParameter('my-params');

EDIT:

You can define your own custom parameters then import in the main config.yml files as example:

config.yml

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: services.yml }
    - { resource: "@ApplicationBundle/Resources/config/parameters.yml" }

hope this help

Upvotes: 5

Related Questions