Answer the question
In order to leave comments, you need to log in
PhalconPHP: problem declaring its own dispatcher in DI?
Tell me what's the problem.
I declare my dispatcher in the container, but it does not work, maybe initialization occurs earlier?
It seems that it does not write to the container because there is already an initialized dispatcher.
But binding DI to the application happens later:
$di = new Phalcon\DI\FactoryDefault();
$di->set('dispatcher', function() use ($di) {
$eventsManager = $di->getShared('eventsManager');
$security = new Security($di);
$eventsManager->attach('dispatch', $security);
$dispatcher = new Phalcon\Mvc\Dispatcher();
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});
Answer the question
In order to leave comments, you need to log in
Alternatively, you can get the default dispatcher via di and work with it without creating a new one.
It is necessary to assign to the variable the services with which we want to work
. Then perform actions and write to the container again
$events = $di->getShared('eventsManager');
$events->attach('dispatch', new Security($di));
$dispatcher = $di->getShared('dispatcher');
$dispatcher->setEventsManager($events);
$di->setShared('dispatcher', $dispatcher);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question