【问题标题】:symfony forward with DIsymfony forward with DI
【发布时间】:2014-03-03 13:46:42
【问题描述】:

我在 symfony2 控制器中有一个 DI 问题

public function __construct(EngineInterface $engine,EntityManager $entityManager,...

配置

acme.acme_controller:
    class: %acme.acme_controller_class%
    arguments:
        - @templating
        - @doctrine.orm.entity_manager
        ...
    calls:
        - [ setContainer, [ @service_container ] ]

如果我在浏览器中显示一个页面,这基本上可以工作,但如果我尝试使用它会中断

$this->forward("Acme:Acme:something", array('id' => $id));

我得到的只是

Argument 1 passed to ::__construct() must implement interface Symfony\Component\Templating\EngineInterface, none given, called in app\cache\dev\classes.php on line 1543 and defined

重定向工作正常,所以我在这里做错了什么? Symfony 2.3.11

【问题讨论】:

    标签: php symfony


    【解决方案1】:

    您需要传递服务 ID(而不是捆绑类名称)才能让 DI 启动。类似于:

    $this->forward("acme.acme_controller:somethingAction", array('id' => $id));
    

    已编辑以根据评论添加操作。

    【讨论】:

    • 谢谢,因为我现在正在尝试,它需要 :somethingAction 就像 :something 以 500 Internal Server Error - InvalidArgumentException 结尾
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-14
    • 2018-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多