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 and Initialize in 1.2.0

If I use:

$eventsManager->attach('dispatch:beforeExecuteRoute', new \Engine\Plugin\CacheAnnotation());

and in plugin:

$annotations = $this->annotations->getMethod(
            $dispatcher->getActiveController(),
            $dispatcher->getActiveMethod()
        );
....

'initialize' is not being called in this case... is it normal? (There is no stopping of event.)



32.5k

I use plugin and exact those rows too, but never noticed problems. What about action? It is strange if action would be called without initialize. I don't think such behaviour is reachable.

Do you have latest origin/1.2.0 branch? If you look at changelog (https://github.com/phalcon/cphalcon/blob/1.2.0/CHANGELOG), you will see such string:

Now if a controller implements 'initialize' it only is called if 'beforeExecuteRoute' is not stopped


32.5k

Yes, I do. I understood what you meant. Actually, this string appeared in changelog because of me :D https://github.com/phalcon/cphalcon/issues/703 I have a lot of important things in initializes and few additional annotations, using same code you have posted on same event. So, If something went wrong I see it immediately on many pages. That's why I can say all is right generally.

Can you try to leave just a test "echo '<func_name> called'" in initialize and beforeExecuteRoute to check execution of these functions? Maybe the problem is elsewhere.

Or you meant that initialize is to called before beforeExecuteRoute? I didn't actually want to change current event sequence when created that issue. I proposed to created additional event, beforeInitialize of something like. Maybe, Phalcon hadn't considered the fact that generally developers need both of event — right before initialization (after beforeDispatch) and right after initialization (before execute action). Second one was beforeExecuteRoute. But now it is the first of them.

If you really need event between initialize & action, a new issue on github is needed to solve this problem. Maybe it is better to revert beforeExecuteRoute and create new event instead (between beforeDispatch & initialize).

Yes, I do. I understood what you meant. Actually, this string appeared in changelog because of me :D https://github.com/phalcon/cphalcon/issues/703
I have a lot of important things in initializes and few additional annotations, using same code you have posted on same event. So, If something went wrong 
I see it immediately on many pages. That's why I can say all is right generally.

Yes, this is important feature.

Can you try to leave just a test "echo '<func_name> called'" in initialize and beforeExecuteRoute to check execution of these functions? Maybe the problem is elsewhere.

I went it with xdebug.

Or you meant that initialize is to called *before* beforeExecuteRoute?
I didn't actually want to change current event sequence when created that issue. I proposed to created additional event, beforeInitialize of something like. Maybe, Phalcon hadn't considered the fact that generally developers need both of event — right before initialization (after beforeDispatch) and right after initialization (before execute action). Second one was beforeExecuteRoute. But now it is the first of them.

If you really need event between initialize & action, a new issue on github is needed to solve this problem. Maybe it is better to revert beforeExecuteRoute and create new event instead (between beforeDispatch & initialize).

No. I think, that event of this plugin (not implementation of beforeExecuteRoute method in base controller class) somehow interrupts the initialization method call (that is implemented in base controller class). Strange that you have no problem... i've got it when update to latest Phalcon. I will create a gist for this.

same thing. if beforeExecuteRoute function just exists in BaseController (for example) no invokation of initialize method happens. and does not matter void return from beforeExecuteRoute or true. but, other subscribers on dispatch:beforeExecuteRoute does not prevents initizlize() call

Same problem here, a complete projects stopped working when tested in 1.2 branch because of not called initialize methods in controllers.

Can not reproduce this in new project (created via phalcon dev-tools) ... but in main project it still present...