Symfony2: ContextErrorException: Catchable Fatal Error: argument 1 passed [...] :: __ construct () should implement the interface [...] none given

Problem:

At any time when I try to access the application, I get this error:

ContextErrorException: Catchable Fatal Error: argument 1 passed PL \ OrderBundle \ Entity \ OrderHasComment :: __ construct () must implement the Symfony \ Component \ Security \ Core \ SecurityContextInterface interface, not a single one called by / var / www / html / apps / portal _de_logistica / vendor / sonata-project / doctrine-orm-admin-bundle / Model / ModelManager.php on line 416 and is defined in / var / www / html / apps / portal _de_logistica / src / PL / OrderBundle / Entity / OrderHasComment.php line 48

What am I doing wrong?

0
source share
1 answer

PL\OrderBundle\Entity\OrderHasComment the constructor requests a required argument, but do not provide it when creating a new instance of the object.

You create a new OrderHasComment (whatever that is):

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

Remove this - it will no longer be needed when your listener calls something like setContext(...), and it does not need to create an object ... therefore it should not be mandatory in any case.

// 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 problem responsible for the exception.

+3
source

Source: https://habr.com/ru/post/1529662/


All Articles