We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Registered dispatcher does not get called


I've a working REST app with routing etc. Actually it responses


Just fine so far. Now I like to add a plugin to the dispatch loop so I added it to the DI but nothing happens. Next I tested if it gets called at all, and unfortunatelly that's not the case.


/** Register default dependencies */
$dependencyInjector = new Phalcon\DI\FactoryDefault(); 

/** Register dispatcher */
    'dispatcher', function () use ($dependencyInjector) {

$application = new Application($dependencyInjector);
echo $application->handle()->getContent();

If I run the code, the response is the same as above, like the dispatcher injection doesn't exist anyway. Some hints what I'm doing wrong?

Best, Thorsten

edited Mar '14


    $di['dispatcher'] = function () use ($di) {
            $eventsManager = $di->getShared('eventsManager');
            $eventsManager->attach('dispatch', new \Path\To\Your\Implementation($di));

            $dispatcher = new Dispatcher();

            return $dispatcher;

Then in your :

namespace Path\To\Your;

use Phalcon\Events\Event,
use Phalcon\Mvc\Dispatcher;

class Implementation
     * beforeDispatchLoop
     * @param  Event                           $event
     * @param  Dispatcher                      $dispatcher
     * @return \Phalcon\Http\ResponseInterface
    public function beforeDispatchLoop(Event $event, Dispatcher $dispatcher)
        // Here you can call die() if you want. 
        // This is one of the correct way to do it

Hi Calin,

thats exactly what I did, except the array notation, but now, I tried that also. After that did not work I tried it with placing a breakpoint within $di['dispatcher'] ... but it never get called. Next step I added the die('called') but the output is always the same, like the dispatcher injection doesn't exist anyway.

index.php: https://pastebin.com/BvFUx0KL dependencies.php: https://pastebin.com/u4rCWyhY


Got it! The modules.php has overwritten it.