我正在使用symfony版本3.4.8。 配置适用于symfony 3.3,但在symfony 3.4中我得到:
Cannot autowire service "ProblemBundle\EntityManager\ProblemManager": argument "$paginator" of metho
d "__construct()" references interface "Knp\Component\Pager\PaginatorInterface" but no such service
exists. Did you create a class that implements this interface?
ProblemManager.php
public function (PaginatorInterface $page){}
应用程序/配置/ services.yml
# Learn more about services, parameters and containers at
# https://symfony.com/doc/current/service_container.html
parameters:
#parameter_name: value
services:
# default configuration for services in *this* file
_defaults:
# automatically injects dependencies in your services
autowire: true
# automatically registers your services as commands, event subscribers, etc.
autoconfigure: true
# this means you cannot fetch services directly from the container via $container->get()
# if you need to do this, you can override this setting on individual services
public: true
# makes classes in src/AppBundle available to be used as services
# this creates a service per class whose id is the fully-qualified class name
# add more services, or override services that need manual wiring
# AppBundle\Service\ExampleService:
# arguments:
# $someArgument: 'some_value'
UserBundle\Controller\:
resource: '../../src/UserBundle/Controller'
public: true
autowire: true
tags: ['controller.service_arguments']
UserBundle\EntityManager\UserManager:
autowire: true
ProblemBundle\EntityManager\ProblemManager:
autowire: true
public: true
如何为所有人(包括第三方捆绑包)配置自动装配?
答案 0 :(得分:1)
指示您希望使用哪个实现的依赖注入组件,例如:
Knp\Component\Pager\PaginatorInterface:
public: true
alias: Your\Solid\Implementation
如果您想使用其他实现,则需要更改此单一配置行。
答案 1 :(得分:0)
您仍然可以通过服务标签注入Non-Autowireable
个参数,在您的情况下它将是
ProblemBundle\EntityManager\ProblemManager:
autowire: true
public: true
arguments:
$page: "@knp_paginator.injectable"