Symfony 3.3自动配置服务和使用

时间:2017-07-15 16:24:36

标签: symfony symfony-3.3

我将我的项目更新为Symfony 3.3。我想为服务使用新的自动配置功能。我试图摆脱$this->get(),但我在控制器和命令中有错误。

下面的代码示例在Controller中,我有这个错误:

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.

在命令中,我根本不知道如何摆脱$container->get()

你知道如何让它发挥作用吗?

控制器:

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

我的配置:

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

编辑:修改config.yml后出现新错误

New error message

1 个答案:

答案 0 :(得分:2)

对于控制器,您还需要在“actions”方法中将服务参数解析器添加到autowire服务。这都是关于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 ]