0

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?

Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130
ReynierPM
  • 17,594
  • 53
  • 193
  • 363

1 Answers1

3

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.

Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130
  • 1
    I fix the issues you tell me but now I get this error `ServiceCircularReferenceException: Circular reference detected for service "doctrine.orm.default_entity_manager", path: "doctrine.orm.default_entity_manager -> doctrine.dbal.default_connection -> orderhascomment.listener -> security.context -> security.authentication.manager -> fos_user.user_manager -> fos_user.entity_manager".` – ReynierPM Mar 02 '14 at 13:31
  • Also, can I do this to set the User? `public function onPrePersist(LifecycleEventArgs $args) { $entity = $args->getEntity(); $entity->setUser(); }` or this is complety wrong? – ReynierPM Mar 02 '14 at 13:32
  • The `onPrePersist` implementation looks okay but there's another problem that involves you injecting the `security.context` service. I can help you with that easily ... but ... my answer obviously **resolved this issue** (the exception-issue that was asked for in this question). Please first upvote/accept the answer and ask a **new question** for your **new exception**. This is how stackoverflow works ... otherwise the page would be a huge mess where nobody would be able to find a solution to a concrete problem quickly :) – Nicolai Fröhlich Mar 02 '14 at 13:36
  • I leave you the question here http://stackoverflow.com/questions/22128402/is-secure-inject-the-whole-container-or-just-security-context – ReynierPM Mar 02 '14 at 13:48