Search code examples
phpsymfonydependency-injectiondoctrine-ormsymfony-2.4

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


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?


Solution

  • 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.