Symfony2: ContextErrorException: Catchable Fatal Error: Argument 1 passed to […]::__construct() must implement interface […] none given

淺唱寂寞╮ 提交于 2020-01-30 11:21:26

问题


The problem:

Any time I try to access the application I get this error:

ContextErrorException: Catchable Fatal Error: Argument 1 passed to PL\OrderBundle\Entity\OrderHasComment::__construct() must implement interface Symfony\Component\Security\Core\SecurityContextInterface, none given, called in /var/www/html/apps/portal_de_logistica/vendor/sonata-project/doctrine-orm-admin-bundle/Model/ModelManager.php on line 416 and defined in /var/www/html/apps/portal_de_logistica/src/PL/OrderBundle/Entity/OrderHasComment.php line 48

What I'm doing wrong?


回答1:


PL\OrderBundle\Entity\OrderHasComment's constructor asks for a mandatory argument but don't you provide it when you create a new instance of the object.

You're creating a new OrderHasComment (whatever that is) like this:

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

Remove that - it won't be needed anymore once your listener calls something like setContext(...) and it's not needed to create the object ... so it shouldn't be mandatory anyways.

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

... should become:

public function __construct()
{

This solves the issue that's responsible for the exception.



来源:https://stackoverflow.com/questions/22127944/symfony2-contexterrorexception-catchable-fatal-error-argument-1-passed-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!