Symfony2:ContextErrorException:Catchable Fatal Error:传递给[...] :: __ construct()的参数1必须实现接口[...] none

时间:2014-03-02 13:07:54

标签: php symfony dependency-injection doctrine-orm symfony-2.4

问题:

每当我尝试访问该应用程序时,都会收到此错误:

  

ContextErrorException:Catchable Fatal Error:传递给的参数1   PL \ OrderBundle \ Entity \ OrderHasComment :: __ construct()必须实现   接口Symfony \ Component \ Security \ Core \ SecurityContextInterface,   没有给出,被称为   /var/www/html/apps/portal_de_logistica/vendor/sonata-project/doctrine-orm-admin-bundle/Model/ModelManager.php   在第416行并在中定义   /var/www/html/apps/portal_de_logistica/src/PL/OrderBundle/Entity/OrderHasComment.php   第48行

我做错了什么?

1 个答案:

答案 0 :(得分:3)

PL\OrderBundle\Entity\OrderHasComment的构造函数请求强制参数,但是在创建对象的新实例时不提供它。

您正在创建一个新的OrderHasComment(无论是什么),如下所示:

$object = new OrderHasComment() // <- missing argument 

删除它 - 一旦你的监听器调用setContext(...)这样的东西就不再需要它了,并且不需要创建对象......所以它不应该是强制性的。

// remove the mandatory argument or provide a default (i.e. $context = null)
public function __construct(ContextInterface $context) /
{
    // ...

......应该成为:

public function __construct()
{

这解决了导致异常的问题。

相关问题