我试图在我的控制器中使用依赖注入。我正在使用FOSRestController。
我收到了一个错误:
捆绑" app.person_rest_controller"不存在或不存在 启用。也许你忘了在registerBundles()方法中添加它 你的AppKernel.php文件?在 /var/www/html/src/AppBundle/Resources/config/routing.yml(这是 从" /var/www/html/app/config/routing.yml")导入。
我的控制器看起来像:
class PersonRestController extends FOSRestController
{
private $entityManager;
private $container;
private $sendNewContactRabbitMQProducer;
public function __construct(EntityManager $entityManager, $container, Producer $rabbitMQProducer)
{
$this->entityManager = $entityManager;
$this->container = $container;
$this->sendNewContactRabbitMQProducer = $rabbitMQProducer;
}
public function postPersonAction(ParamFetcher $paramFetcher)
{
...
}
我的routing.yml:
service_person:
type: rest
prefix: /v1
resource: "@app.person_rest_controller"
name_prefix: api_1_ # naming collision
我的services.yml:
services:
app.person_rest_controller:
class: AppBundle\Controller\PersonRestController
arguments:
- "@doctrine.orm.entity_manager"
- "@service_container"
- "@person.rabbitmq.producer.send_new_contact"
person.rabbitmq.producer.send_new_contact:
class: AppBundle\Service\SendNewContactRabbitMQProducer
arguments: []
calls:
- [setRabbitMQProducer, ["@old_sound_rabbit_mq.send_person_id_from_hotelpro4u_producer"]]
- [setLogger, ['@logger']]
我的工作基于此:https://github.com/FriendsOfSymfony/FOSRestBundle/issues/990
一个想法?
谢谢! =)
答案 0 :(得分:0)
两件快事,特别是因为您似乎有一条实际上对您有帮助的错误消息:
official Symfony documentation解释了这两个问题
通常,您会在/symfony/project/root/doc/app/AppKernel.php
答案 1 :(得分:0)
我创建了解决方案,这是一个愚蠢的错误:
服务控制器在名称前没有@。
更改:
service_person:
type: rest
prefix: /v1
resource: "@app.person_rest_controller"
name_prefix: api_1_ # naming collision
到此:
service_person:
type: rest
prefix: /v1
resource: "app.person_rest_controller"
name_prefix: api_1_ # naming collision