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

Using events with micro applications

I have a problem firing beforeExecuteRoute as I am using micro collections in a micro application.


You can upload code?

Try playing with this block of code, just change it to beforeExecuteRoute: https://gist.github.com/JREAM/d0722c5996ffd0c4d26c

I am using a micro application, and the event is not fired, that's it.


You have to use the following code:


use Phalcon\Mvc\Micro,
    Phalcon\Events\Manager as EventsManager;

//Create a events manager
$eventManager = new EventsManager();

//Listen all the application events
$eventManager->attach('micro', function($event, $app) {

    if ($event->getType() == 'beforeExecuteRoute') {
        if ($app->session->get('auth') == false) {

            $app->flashSession->error("The user isn't authenticated");

            //Return (false) stop the operation
            return false;


$app = new Micro();

//Bind the events manager to the app


edited Jul '14

@Phalcon I am using micro collections to forward the requests to contorlloers, I need this event to be fired in certain contorllers, and others are not. Any ideas?