Symfony 3.3 services and autoconfiguration

I have updated my project to Symfony 3.3. I want to use the new autoconfiguration feature for services. I tried to get rid of $this->get()

, but I have errors in controllers and commands.

With the sample code below in my controller, I have this error:

recapitulatifCollesAction() requires that you provide a value for the "$checkGele" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.

      

In teams, I don't know at all how to get rid of $container->get()

.

Do you have any idea how I can get this to work?

Controller:

public function recapitulatifCollesAction($estEnCours, CheckGeleService $checkGele)
{
    // ...
    $checkGele->getGeleAutorisation($colle);
    // ...
}

      

My config:

services:
    _defaults:
        autowire: true
        autoconfigure: true
        public: false

      

Edit: new error after changing config.yml

New error message

+3


source to share


1 answer


For controllers, you also need to add the service argument argument to the autowire service in the "action" methods. This is all about default auto-arming in version 3.3:



services:
    _defaults:
        autowire: true
        autoconfigure: true
        public: false

    AppBundle\:
        resource: '../../src/AppBundle/*'
        exclude: '../../src/AppBundle/{Controller, Entity, Repository}'

    AppBundle\Controller\:
        resource: '../../src/AppBundle/Controller'
        public: true
        tags: [ controller.service_arguments ]

      

+3


source







All Articles