Giancarlo Ventura Granados Giancarlo Ventura Granados - 3 months ago 9
PHP Question

Use paramater value in a custom class (Symfony2)

I have some parameter values in app/config/parameters.yml

parameters:
database_host: 127.0.0.1
database_port: null
database_name: database_name
...
igv: 0.18
isc: 0.18


Now, I want to use the parameters in a Custom class in AppBundle/CustomClass.php. How can I use this parameters? I try $this->container->get('igv') but not works.

Answer

In services.yml:

my_app.customclass:
    class:  AppBundle\CustomClass
    arguments: ['%igv%', '%isc%']

Add the arguments to the constructor of AppBundle\CustomClass.