Configuring Symfony

Configuration Files

Symfony applications are configured with the files stored in the config/directory, which has this default structure:

  1. your-project/
  2. ├─ config/
  3. ├─ packages/
  4. ├─ bundles.php
  5. ├─ routes.yaml
  6. └─ services.yaml
  7. ├─ ...

The routes.yaml file defines the routing configuration;the services.yaml file configures the services of theservice container; the bundles.php file enables/disables packages in your application.

You'll be working most in the config/packages/ directory. This directorystores the configuration of every package installed in your application.Packages (also called "bundles" in Symfony and "plugins/modules" in otherprojects) add ready-to-use features to your projects.

When using Symfony Flex, which is enabled by default inSymfony applications, packages update the bundles.php file and create newfiles in config/packages/ automatically during their installation. Forexample, this is the default file created by the "API Platform" package:

  1. # config/packages/api_platform.yaml
  2. api_platform:
  3. mapping:
  4. paths: ['%kernel.project_dir%/src/Entity']

Splitting the configuration into lots of small files is intimidating for someSymfony newcomers. However, you'll get used to them quickly and you rarely needto change these files after package installation

Tip

To learn about all the available configuration options, check out theSymfony Configuration Reference or run theconfig:dump-reference command.

Configuration Formats

Unlike other frameworks, Symfony doesn't impose you a specific format toconfigure your applications. Symfony lets you choose between YAML, XML and PHPand throughout the Symfony documentation, all configuration examples will beshown in these three formats.

There isn't any practical difference between formats. In fact, Symfonytransforms and caches all of them into PHP before running the application, sothere's not even any performance difference between them.

YAML is used by default when installing packages because it's concise and veryreadable. These are the main advantages and disadvantages of each format:

  • YAML: simple, clean and readable, but not all IDEs support autocompletionand validation for it. Learn the YAML syntax;
  • XML:autocompleted/validated by most IDEs and is parsed natively by PHP,but sometimes it generates too verbose configuration. Learn the XML syntax;
  • PHP: very powerful and it allows to create dynamic configuration, but theresulting configuration is less readable than the other formats.

Importing Configuration Files

Symfony loads configuration files using the Config component, which provides advanced features such as importing otherconfiguration files, even if they use a different format:

  • YAML
  1. # config/services.yaml
  2. imports:
  3. - { resource: 'legacy_config.php' }
  4. # ignore_errors silently discards errors if the loaded file doesn't exist
  5. - { resource: 'my_config_file.xml', ignore_errors: true }
  6. # glob expressions are also supported to load multiple files
  7. - { resource: '/etc/myapp/*.yaml' }
  8.  
  9. # ...
  • XML
  1. <!-- config/services.xml -->
  2. <?xml version="1.0" encoding="UTF-8" ?>
  3. <container xmlns="http://symfony.com/schema/dic/services"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xsi:schemaLocation="http://symfony.com/schema/dic/services
  6. https://symfony.com/schema/dic/services/services-1.0.xsd
  7. http://symfony.com/schema/dic/symfony
  8. https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
  9.  
  10. <imports>
  11. <import resource="legacy_config.php"/>
  12. <!-- ignore_errors silently discards errors if the loaded file doesn't exist -->
  13. <import resource="my_config_file.yaml" ignore-errors="true"/>
  14. <!-- glob expressions are also supported to load multiple files -->
  15. <import resource="/etc/myapp/*.yaml"/>
  16. </imports>
  17.  
  18. <!-- ... -->
  19. </container>
  • PHP
  1. // config/services.php
  2. $loader->import('legacy_config.xml');
  3. // the third optional argument of import() is 'ignore_errors', which
  4. // silently discards errors if the loaded file doesn't exist
  5. $loader->import('my_config_file.yaml', null, true);
  6. // glob expressions are also supported to load multiple files
  7. $loader->import('/etc/myapp/*.yaml');
  8.  
  9. // ...

Configuration Parameters

Sometimes the same configuration value is used in several configuration files.Instead of repeating it, you can define it as a "parameter", which is like areusable configuration value. By convention, parameters are defined under theparameters key in the config/services.yaml file:

  • YAML
  1. # config/services.yaml
  2. parameters:
  3. # the parameter name is an arbitrary string (the 'app.' prefix is recommended
  4. # to better differentiate your parameters from Symfony parameters).
  5. app.admin_email: '[email protected]'
  6.  
  7. # boolean parameters
  8. app.enable_v2_protocol: true
  9.  
  10. # array/collection parameters
  11. app.supported_locales: ['en', 'es', 'fr']
  12.  
  13. # binary content parameters (encode the contents with base64_encode())
  14. app.some_parameter: !!binary VGhpcyBpcyBhIEJlbGwgY2hhciAH
  15.  
  16. # PHP constants as parameter values
  17. app.some_constant: !php/const GLOBAL_CONSTANT
  18. app.another_constant: !php/const App\Entity\BlogPost::MAX_ITEMS
  19.  
  20. # ...
  • XML
  1. <!-- config/services.xml -->
  2. <?xml version="1.0" encoding="UTF-8" ?>
  3. <container xmlns="http://symfony.com/schema/dic/services"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xmlns:framework="http://symfony.com/schema/dic/symfony"
  6. xsi:schemaLocation="http://symfony.com/schema/dic/services
  7. https://symfony.com/schema/dic/services/services-1.0.xsd
  8. http://symfony.com/schema/dic/symfony
  9. https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
  10.  
  11. <parameters>
  12. <!-- the parameter name is an arbitrary string (the 'app.' prefix is recommended
  13. to better differentiate your parameters from Symfony parameters). -->
  14. <parameter key="app.admin_email">[email protected]</parameter>
  15.  
  16. <!-- boolean parameters -->
  17. <parameter key="app.enable_v2_protocol">true</parameter>
  18. <!-- if you prefer to store the boolean value as a string in the parameter -->
  19. <parameter key="app.enable_v2_protocol" type="string">true</parameter>
  20.  
  21. <!-- array/collection parameters -->
  22. <parameter key="app.supported_locales" type="collection">
  23. <parameter>en</parameter>
  24. <parameter>es</parameter>
  25. <parameter>fr</parameter>
  26. </parameter>
  27.  
  28. <!-- binary content parameters (encode the contents with base64_encode()) -->
  29. <parameter key="app.some_parameter" type="binary">VGhpcyBpcyBhIEJlbGwgY2hhciAH</parameter>
  30.  
  31. <!-- PHP constants as parameter values -->
  32. <parameter key="app.some_constant" type="constant">GLOBAL_CONSTANT</parameter>
  33. <parameter key="app.another_constant" type="constant">App\Entity\BlogPost::MAX_ITEMS</parameter>
  34. </parameters>
  35.  
  36. <!-- ... -->
  37. </container>
  • PHP
  1. // config/services.php
  2. // the parameter name is an arbitrary string (the 'app.' prefix is recommended
  3. // to better differentiate your parameters from Symfony parameters).
  4. $container->setParameter('app.admin_email', '[email protected]');
  5.  
  6. // boolean parameters
  7. $container->setParameter('app.enable_v2_protocol', true);
  8.  
  9. // array/collection parameters
  10. $container->setParameter('app.supported_locales', ['en', 'es', 'fr']);
  11.  
  12. // binary content parameters (use the PHP escape sequences)
  13. $container->setParameter('app.some_parameter', 'This is a Bell char: \x07');
  14.  
  15. // PHP constants as parameter values
  16. use App\Entity\BlogPost;
  17.  
  18. $container->setParameter('app.some_constant', GLOBAL_CONSTANT);
  19. $container->setParameter('app.another_constant', BlogPost::MAX_ITEMS);
  20.  
  21. // ...

Caution

When using XML configuration, the values between <parameter> tags arenot trimmed. This means that the value of the following parameter will be'\n something@example.com\n':

  1. <parameter key="app.admin_email">
  2. [email protected]
  3. </parameter>

Once defined, you can reference this parameter value from any otherconfiguration file using a special syntax: wrap the parameter name in two %(e.g. %app.admin_email%):

  • YAML
  1. # config/packages/some_package.yaml
  2. some_package:
  3. # any string surrounded by two % is replaced by that parameter value
  4. email_address: '%app.admin_email%'
  5.  
  6. # ...
  • XML
  1. <!-- config/packages/some_package.xml -->
  2. <?xml version="1.0" encoding="UTF-8" ?>
  3. <container xmlns="http://symfony.com/schema/dic/services"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xmlns:framework="http://symfony.com/schema/dic/symfony"
  6. xsi:schemaLocation="http://symfony.com/schema/dic/services
  7. https://symfony.com/schema/dic/services/services-1.0.xsd
  8. http://symfony.com/schema/dic/symfony
  9. https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
  10.  
  11. <!-- any string surrounded by two % is replaced by that parameter value -->
  12. <some-package:config email-address="%app.admin_email%">
  13. <!-- ... -->
  14. </some-package:config>
  15. </container>
  • PHP
  1. // config/packages/some_package.php
  2. $container->loadFromExtension('some_package', [
  3. // any string surrounded by two % is replaced by that parameter value
  4. 'email_address' => '%app.admin_email%',
  5.  
  6. // ...
  7. ]);

Note

If some parameter value includes the % character, you need to escape itby adding another % so Symfony doesn't consider it a reference to aparameter name:

  • YAML
  1. # config/services.yaml
  2. parameters:
  3. # Parsed as 'https://symfony.com/?foo=%s&amp;bar=%d'
  4. url_pattern: 'https://symfony.com/?foo=%%s&amp;bar=%%d'
  • XML
  1. <!-- config/services.xml -->
  2. <parameters>
  3. <parameter key="url_pattern">http://symfony.com/?foo=%%s&amp;bar=%%d</parameter>
  4. </parameters>
  • PHP
  1. // config/services.php
  2. $container->setParameter('url_pattern', 'http://symfony.com/?foo=%%s&amp;bar=%%d');

Note

Due to the way in which parameters are resolved, you cannot use themto build paths in imports dynamically. This means that something likethe following doesn't work:

  • YAML
  1. # config/services.yaml
  2. imports:
  3. - { resource: '%kernel.project_dir%/somefile.yaml' }
  • XML
  1. <!-- config/services.xml -->
  2. <?xml version="1.0" encoding="UTF-8" ?>
  3. <container xmlns="http://symfony.com/schema/dic/services"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xsi:schemaLocation="http://symfony.com/schema/dic/services
  6. https://symfony.com/schema/dic/services/services-1.0.xsd">
  7.  
  8. <imports>
  9. <import resource="%kernel.project_dir%/somefile.yaml"/>
  10. </imports>
  11. </container>
  • PHP
  1. // config/services.php
  2. $loader->import('%kernel.project_dir%/somefile.yaml');

Configuration parameters are very common in Symfony applications. Some packageseven define their own parameters (e.g. when installing the translation package,a new locale parameter is added to the config/services.yaml file).

Later in this article you can read how toref:get configuration parameters in controllers and services <configuration-accessing-parameters>.

Configuration Environments

You have just one application, but whether you realize it or not, you need itto behave differently at different times:

  • While developing, you want to log everything and expose nice debugging tools;
  • After deploying to production, you want that same application to beoptimized for speed and only log errors.The files stored in config/packages/ are used by Symfony to configure theapplication services. In other words, you can changethe application behavior by changing which configuration files are loaded.That's the idea of Symfony's configuration environments.

A typical Symfony application begins with three environments: dev (for localdevelopment), prod (for production servers) and test (forautomated tests). When running the application, Symfony loadsthe configuration files in this order (the last files can override the valuesset in the previous ones):

  • config/packages/.yaml (and .xml and .php files too);
  • config/packages/<environment-name>/.yaml (and .xml and .php files too);
  • config/packages/services.yaml (and services.xml and services.php files too);Take the framework package, installed by default, as an example:

  • First, config/packages/framework.yaml is loaded in all environments andit configures the framework with some options;

  • In the prod environment, nothing extra will be set as there is noconfig/packages/prod/framework.yaml file;
  • In the dev environment, there is no file either (config/packages/dev/framework.yaml does not exist).
  • In the test environment, the config/packages/test/framework.yaml fileis loaded to override some of the settings previously configured inconfig/packages/framework.yaml.In reality, each environment differs only somewhat from others. This means thatall environments share a large base of common configurations, which is put infiles directly in the config/packages/ directory.

See the configureContainer() method ofthe Kernel class tolearn everything about the loading order of configuration files.

Selecting the Active Environment

Symfony applications come with a file called .env located at the projectroot directory. This file is used to define the value of environment variablesand it's explained in detail later in this article.

Open the .env file (or better, the .env.local file if you created one)and edit the value of the APP_ENV variable to change the environment inwhich the application runs. For example, to run the application in production:

  1. # .env (or .env.local)
  2. APP_ENV=prod

This value is used both for the web and for the console commands. However, youcan override it for commands by setting the APP_ENV value before running them:

  1. # Use the environment defined in the .env file
  2. $ php bin/console command_name
  3.  
  4. # Ignore the .env file and run this command in production
  5. $ APP_ENV=prod php bin/console command_name

Creating a New Environment

The default three environments provided by Symfony are enough for most projects,but you can define your own environments too. For example, this is how you candefine a staging environment where the client can test the project beforegoing to production:

  • Create a configuration directory with the same name as the environment (inthis case, config/packages/staging/);
  • Add the needed configuration files in config/packages/staging/ todefine the behavior of the new environment. Symfony loads first the files inconfig/packages/*.yaml, so you must only configure the differences withthose files;
  • Select the staging environment using the APP_ENV env var as explainedin the previous section.

Tip

It's common for environments to be similar between each other, so you canuse symbolic links between config/packages/<environment-name>/directories to reuse the same configuration.

Configuration Based on Environment Variables

Using environment variables (or "env vars" for short) is a common practice toconfigure options that depend on where the application is run (e.g. the databasecredentials are usually different in production and in your local machine).

Instead of defining those as regular options, you can define them as environmentvariables and reference them in the configuration files using the special syntax%env(ENV_VAR_NAME)%. The values of these options are resolved at runtime(only once per request, to not impact performance).

This example shows how to configure the database connection using an env var:

  • YAML
  1. # config/packages/doctrine.yaml
  2. doctrine:
  3. dbal:
  4. # by convention the env var names are always uppercase
  5. url: '%env(DATABASE_URL)%'
  6. # ...
  • XML
  1. <!-- config/packages/doctrine.xml -->
  2. <?xml version="1.0" encoding="UTF-8" ?>
  3. <container xmlns="http://symfony.com/schema/dic/services"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xmlns:doctrine="http://symfony.com/schema/dic/doctrine"
  6. xsi:schemaLocation="http://symfony.com/schema/dic/services
  7. https://symfony.com/schema/dic/services/services-1.0.xsd
  8. http://symfony.com/schema/dic/doctrine
  9. https://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
  10.  
  11. <doctrine:config>
  12. <!-- by convention the env var names are always uppercase -->
  13. <doctrine:dbal url="%env(DATABASE_URL)%"/>
  14. </doctrine:config>
  15.  
  16. </container>
  • PHP
  1. // config/packages/doctrine.php
  2. $container->loadFromExtension('doctrine', [
  3. 'dbal' => [
  4. // by convention the env var names are always uppercase
  5. 'url' => '%env(DATABASE_URL)%',
  6. ]
  7. ]);

The next step is to define the value of those env vars in your shell, your webserver, etc. This is explained in the following sections, but to protect yourapplication from undefined env vars, you can give them a default value using the.env file:

  1. # .env
  2. DATABASE_URL=sqlite:///%kernel.project_dir%/var/data.db

The values of env vars can only be strings, but Symfony includes someenv var processors to transformtheir contents (e.g. to turn a string value into an integer).

In order to define the actual values of env vars, Symfony proposes differentsolutions depending if the application is running in production or in your localdevelopment machine.

Independent from the way you set environment variables, you may need to run thedebug:container command with the —env-vars option to verify that theyare defined and have the expected values:

  1. $ php bin/console debug:container --env-vars
  2.  
  3. ---------------- ----------------- ---------------------------------------------
  4. Name Default value Real value
  5. ---------------- ----------------- ---------------------------------------------
  6. APP_SECRET n/a "471a62e2d601a8952deb186e44186cb3"
  7. FOO "[1, "2.5", 3]" n/a
  8. BAR null n/a
  9. ---------------- ----------------- ---------------------------------------------
  10.  
  11. # you can also filter the list of env vars by name:
  12. $ php bin/console debug:container --env-vars foo
  13.  
  14. # run this command to show all the details for a specific env var:
  15. $ php bin/console debug:container --env-var=FOO

New in version 4.3: The option to debug environment variables was introduced in Symfony 4.3.

Configuring Environment Variables in Development

Instead of defining env vars in your shell or your web server, Symfony proposesa convenient way of defining them in your local machine based on a file called.env (with a leading dot) located at the root of your project.

The .env file is read and parsed on every request and its env vars are addedto the $_ENV PHP variable. The existing env vars are never overwritten bythe values defined in .env, so you can combine both.

This is for example the content of the .env file to define the value of theDATABASE_URL env var shown earlier in this article:

  1. # .env
  2. DATABASE_URL="mysql://db_user:[email protected]:3306/db_name"

In addition to your own env vars, this .env file also contains the env varsdefined by the third-party packages installed in your application (they areadded automatically by Symfony Flex when installing packages).

Configuring Environment Variables in Production

In production, the .env files are also parsed and loaded on each request soyou can override the env vars already defined in the server. In order to improveperformance, you can run the dump-env command (available when usingSymfony Flex 1.2 or later).

This command parses all the .env files once and compiles their contents intoa new PHP-optimized file called .env.local.php. From that moment, Symfonywill load the parsed file instead of parsing the .env files again:

  1. $ composer dump-env prod

Tip

Update your deployment tools/workflow to run the dump-env command aftereach deploy to improve the application performance.

Creating .env files is the easiest way of using env vars in Symfonyapplications. However, you can also configure real env vars in your servers andoperating systems.

Tip

SymfonyCloud, the cloud service optimized for Symfony applications, definessome utilities to manage env vars in production.

Caution

Beware that dumping the contents of the $_SERVER and $_ENV variablesor outputting the phpinfo() contents will display the values of theenvironment variables, exposing sensitive information such as the databasecredentials.

The values of the env vars are also exposed in the web interface of theSymfony profiler. In practice this shouldn't be aproblem because the web profiler must never be enabled in production.

Managing Multiple .env Files

The .env file defines the default values for all env vars. However, it'scommon to override some of those values depending on the environment (e.g. touse a different database for tests) or depending on the machine (e.g. to use adifferent OAuth token on your local machine while developing).

That's why you can define multiple .env files to override env vars. Thefollowing list shows the files loaded in all environments. The .env file isthe only mandatory file and each file content overrides the previous one:

  • .env: defines the default values of the env vars needed by the application;
  • .env.local: defines machine-specific overrides for env vars on allenvironments. This file is not committed to the repository, so these overridesonly apply to the machine which contains the file (your local computer,production server, etc.);
  • .env.<environment> (e.g. .env.test): overrides env vars only for someenvironment but for all machines;
  • .env.<environment>.local (e.g. .env.test.local): defines machine-specificenv vars overrides only for some environment. It's similar to .env.local,but the overrides only apply to some particular environment.

Note

The real environment variables defined in the server always win over theenv vars created by the .env files.

The .env and .env.<environment> files should be committed to the sharedrepository because they are the same for all developers and machines. However,the env files ending in .local (.env.local and .env.<environment>.local)should not be committed because only you will use them. In fact, the.gitignore file that comes with Symfony prevents them from being committed.

Caution

Applications created before November 2018 had a slightly different system,involving a .env.dist file. For information about upgrading, see:Nov 2018 Changes to .env & How to Update.

Accessing Configuration Parameters

Controllers and services can access all the configuration parameters. Thisincludes both the parameters defined by yourselfand the parameters created by packages/bundles. Run the following command to seeall the parameters that exist in your application:

  1. $ php bin/console debug:container --parameters

In controllers extending from the AbstractController,use the getParameter() helper:

  1. // src/Controller/UserController.php
  2. namespace App\Controller;
  3.  
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5.  
  6. class UserController extends AbstractController
  7. {
  8. // ...
  9.  
  10. public function index()
  11. {
  12. $projectDir = $this->getParameter('kernel.project_dir');
  13. $adminEmail = $this->getParameter('app.admin_email');
  14.  
  15. // ...
  16. }
  17. }

In services and controllers not extending from AbstractController, injectthe parameters as arguments of their constructors. You must inject themexplicitly because service autowiringdoesn't work for parameters:

  • YAML
  1. # config/services.yaml
  2. parameters:
  3. app.contents_dir: '...'
  4.  
  5. services:
  6. App\Service\MessageGenerator:
  7. arguments:
  8. $contentsDir: '%app.contents_dir%'
  • XML
  1. <!-- config/services.xml -->
  2. <?xml version="1.0" encoding="UTF-8" ?>
  3. <container xmlns="http://symfony.com/schema/dic/services"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xsi:schemaLocation="http://symfony.com/schema/dic/services
  6. https://symfony.com/schema/dic/services/services-1.0.xsd">
  7.  
  8. <parameters>
  9. <parameter key="app.contents_dir">...</parameter>
  10. </parameters>
  11.  
  12. <services>
  13. <service id="App\Service\MessageGenerator">
  14. <argument key="$contentsDir">%app.contents_dir%</argument>
  15. </service>
  16. </services>
  17. </container>
  • PHP
  1. // config/services.php
  2. use App\Service\MessageGenerator;
  3. use Symfony\Component\DependencyInjection\Reference;
  4.  
  5. $container->setParameter('app.contents_dir', '...');
  6.  
  7. $container->getDefinition(MessageGenerator::class)
  8. ->setArgument('$contentsDir', '%app.contents_dir%');

If you inject the same parameters over and over again, use instead theservices._defaults.bind option. The arguments defined in that option areinjected automatically whenever a service constructor or controller actiondefine an argument with that exact name. For example, to inject the value of thekernel.project_dir parameterwhenever a service/controller defines a $projectDir argument, use this:

  • YAML
  1. # config/services.yaml
  2. services:
  3. _defaults:
  4. bind:
  5. # pass this value to any $projectDir argument for any service
  6. # that's created in this file (including controller arguments)
  7. $projectDir: '%kernel.project_dir%'
  8.  
  9. # ...
  • XML
  1. <!-- config/services.xml -->
  2. <?xml version="1.0" encoding="UTF-8" ?>
  3. <container xmlns="http://symfony.com/schema/dic/services"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xsi:schemaLocation="http://symfony.com/schema/dic/services
  6. https://symfony.com/schema/dic/services/services-1.0.xsd">
  7.  
  8. <services>
  9. <defaults autowire="true" autoconfigure="true" public="false">
  10. <!-- pass this value to any $projectDir argument for any service
  11. that's created in this file (including controller arguments) -->
  12. <bind key="$projectDir">%kernel.project_dir%</bind>
  13. </defaults>
  14.  
  15. <!-- ... -->
  16. </services>
  17. </container>
  • PHP
  1. // config/services.php
  2. use App\Controller\LuckyController;
  3. use Psr\Log\LoggerInterface;
  4. use Symfony\Component\DependencyInjection\Reference;
  5.  
  6. $container->register(LuckyController::class)
  7. ->setPublic(true)
  8. ->setBindings([
  9. // pass this value to any $projectDir argument for any service
  10. // that's created in this file (including controller arguments)
  11. '$projectDir' => '%kernel.project_dir%',
  12. ])
  13. ;

Read the article about binding arguments by name and/or typeto learn more about this powerful feature.

Finally, if some service needs to access to lots of parameters, instead ofinjecting each of them individually, you can inject all the applicationparameters at once by type-hinting any of its constructor arguments with theContainerBagInterface:

  1. // src/Service/MessageGenerator.php
  2. // ...
  3.  
  4. use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
  5.  
  6. class MessageGenerator
  7. {
  8. private $params;
  9.  
  10. public function __construct(ContainerBagInterface $params)
  11. {
  12. $this->params = $params;
  13. }
  14.  
  15. public function someMethod()
  16. {
  17. // get any container parameter from $this->params, which stores all of them
  18. $sender = $this->params->get('mailer_sender');
  19. // ...
  20. }
  21. }

Keep Going!

Congratulations! You've tackled the basics in Symfony. Next, learn about _each_part of Symfony individually by following the guides. Check out: