I have question about Symfony
container. I tried to find some informations about how variables are returned.
For example, config.yml
to my controller, where I want get this value.
Question: config.yml
my_var: 12345
Controller: DefaultController.php
public function testAction(){
die($this->get('my_var'));
}
How does the controller
get the value of my_var
?
Your custom parameter has to live in the parameters domain of your config.yml
# config.yml
parameters:
locale: en
my_var: 12345
Then you can use the container method getParameter()
inside your code. That is if the container is available.
$this->container->getParameter('my_var')
Inside a class extending Controller.php
(or any other class implementing ContainerInterface) you can simply write
$this->getParameter('my_var')
which in turn calls the method above inside the super class.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.