Error starting Silex 2 addListener

I am trying to add an event listener / dispatcher to one of my controller actions. The goal is to add default data to my object before continuing in my database.

Here is what I got so far.

app.php

$app['dispatcher']->addListener('my_event_name', function (Event $event) {
    // do something;
});

As a result, the following error appears:

(!) InvalidArgumentException: The dispatcher identifier does not contain an object definition. in /var/www/site/vendor/pimple/pimple/src/Pimple/Container.php on line 233

+4
source share
1 answer

Check out this thread. This seems to be related to the exact order in which you invoke and initialize.

$this->before(function () {
    $this['dispatcher']->addListener($eventName, $callback);
});

https://github.com/silexphp/Silex-WebProfiler/issues/70#issuecomment-170399805

+1

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


All Articles