You are viewing revision #1 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.
There came the need to perform two operations, always, on 'application boot' time. Example? My real world example involved some geo-location logic (that's the first operation) and syncing of some session details so KcFinder can be in sync with the user in context - each user with his own session container (the second).
Researching around ¶
So anyone who ever attached a single handler to CWebApplication.onBeginRequest knows its easily done by modifying config/main.php like this (for example):
return array( ... // that's php 5.4 array notation below... 'onBeginRequest' => ['SomeClass', 'someStaticMethod'], 'import => [...], 'modules' => [...], ... );
That's nice but its not possible at the moment to attach several event handlers at the same time.
I've followed the suggestions described in this old bug report and altered index.php accordingly, so from this:
I came to this:
require_once($yii); $webapp = Yii::createWebApplication($config); $webapp->onBeginRequest = ['MyClassA', 'staticMethodA']; $webapp->onBeginRequest = ['MyClassB', 'staticMethodB']; $webapp->run();
A quick debugging revealed - both methods are being called exactly as presumed. QED.