PradoSoft

Application lifecycle events

From PRADO Wiki

There is something beyond onInit(), onLoad(), onPreRender() and onUnLoad().

If you have some component not extended from TWebControl. You maybe have to trigger an event to a certain time. But, there is no onInit(), etc... in i.e. TModule.

But you can add an event-handler to any TComponent at any stage of the Application Lifecycle, by

 
<?php
class MyModule extends TModule{
    /*/
    TModule has only no LifeCycle methods. It has only "init($config)".
    Sometimes you need a lifecycle in a TModule, like in this instance where we want access to the 'User' object. 
    During the natural "init($config)", the 'User' object has not yet been created. 
    So, we need to ''borrow'' a lifecycle event from the TApplication. In this case: OnAuthenticationComplete.
    /*/
 
    public function init($config){
        //var_dump($this->User); //returns NULL :(
        $this->Application->OnAuthenticationComplete[] = array($this, 'OnAuthenticationComplete');
    }
 
    //This method could be named anything, as long as it's the same as the 2nd param in the array above.
    public function OnAuthenticationComplete(){
        var_dump($this->User); //success!
    }
}
?>

credits to FragMaster B

The above code accesses the User object when authentication has been completed. Otherwise, if you would access it earlier, you would get an empty/null value.

The originating thread: http://www.pradosoft.com/forum/index.php/topic,4987.0.html

Personal tools
Your user name:

Your password:

MediaWiki