Symfony 3.4, use parameters.yml in controller

0

I want to read a record of parameters.yml in a controller. I do not know why but with Swift Mailer it works for me, but not in any other way. This I am trying:

//Mi Controller
class ExampleController extends Controller
{
    function someMethod($argument)
    {
        dump($this->getParameter('free_proxy'));die();

Here I have in parameters.yml:

parameters:
    free_proxy: "http://xxx:8080"

I get the error: Call to a member function getParameter() on null

I also tried like this:

services:
    _defaults:
        autowire: true
        autoconfigure: true
        public: false
        bind:
          $freeProxy: '%free_proxy%'

And then with:

$this->container->getParameter('free_proxy');

And I get: Unused binding "$freeProxy" in service...

How then can I use a simple log in the controller? Like I said, with Swift Mailer there's no problem when I use:

$message = \Swift_Message::newInstance()->setSubject($this->getParameter('mailer_subjet'))  etc...

I can read "mailer_subject" which is in parameters.yml, but why not the other one?

    
asked by pmirnd 02.01.2019 в 20:36
source

0 answers