We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

beforeExecuteRoute priority

"beforeExecuteRoute" as Controller method are always executed before event listener method.

<?php
class SomeListener
{
    public function beforeExecuteRoute() {
        echo __METHOD__, '<br/>';
    }
}

class PostsController extends \Phalcon\Mvc\Controller
{
    public function beforeExecuteRoute() {
        echo __METHOD__, '<br/>';
    }

    public function initialize() {
        echo __METHOD__, '<br/>';
    }

    public function indexAction(){}
}

$di = new Phalcon\DI\FactoryDefault;

$eventsManager = $di->get('eventsManager');
$eventsManager->attach('dispatch', new SomeListener);

$dispatcher = new Phalcon\Mvc\Dispatcher;
$dispatcher->setDI($di);
$dispatcher->setControllerName('posts');
$dispatcher->setEventsManager($eventsManager);
$dispatcher->dispatch();

// PostsController::initialize
// PostsController::beforeExecuteRoute
// SomeListener::beforeExecuteRoute

Is it possible to execute listener method before controller method? i.e.: PostsController::initialize SomeListener::beforeExecuteRoute PostsController::beforeExecuteRoute



98.9k

I changed the order in 1.2.0, can you try please?