The Page Request Cycle

When a client makes a request to view a web page, the framework will load your Page-Controller logic and allow you to load and process your html views using simple css selectors (for example #id, .classname, etc). Once processing is completed, a reply is sent back to the client that made the request. The replied text contains your html code and may include embedded JavaScript/CSS stylesheet.

If a request was made via an Ajax call, then a JSON object is returned to the client. The returned JSON object may include the action scripts (a mixed of jQuery and JavaScripts) needed to carry out a specific task within the client's web browser.

Page event handler are prefixed with an "_" as shown in the example below:

<?php
    require_once('raxan/pdi/autostart.php');

    class NewPage extends RaxanWebPage {

        protected function _init() {
            $this->append('* This is the init handler <br />');
        }

        protected function _load() {
            $this->append('* This is the load handler <br />');
        }

        protected function _prerender() {
            $this->append('* This is the prerender handler <br />');
        }

    }
?>

Asynchronous/Synchronous Page Request Execution

  • Config - Called before the page is initialized. Used for configuring page properties
  • Init - Called after the page object is created. Used for initializing connections and loading page source
  • Authorize - Used to secure or grant access to the page. Returns true or false to grant or deny access to the page
  • View Handler - Called when a view is requested. Defaults to _indexView.
  • Load - Used for loading additional views/content into web page.
  • Custom Event Request Handler - Triggers the event raised by client
  • PreRender - Used for making final modifications to page just before html is extracted from the DOM
  • PostRender - Called after the HTML is extracted from the DOM and all external and internal processing have been completed
  • Reply - Called just after the HTML/JSON content is sent back to the client.
  • Destroy - Called before the page object is destroyed; Can be used to close open connections etc

Data Reset handler

  • Reset - This handler is called before the page data storage is reset. The resetOnFirstLoad page property must be set to true in order for the data to be reset on first load. To prevent the data from being reset the handler must return false.

For example:

<?php
class MainPage extends RaxanWebPage {

    protected function _reset() {
        if ($this->someProperty == true) {
            return false; // tell the framework not to reset page data
        }
    }
}
?>

Using the Authorize event handler

The authorize event handler can be used to grant or deny access to a web page by returning either a true or false value when invoked.

<?php
class LoginPage extends RaxanWebPage {

    protected function _authorize() {
        $isLogin = $this->Raxan->data('user-login');
        if ($isLogin) $this->redirectTo('mainaccess.php'); // redirect to main page
        return true; // tell the framework to continue
    }
}
?>

A developer can use the event to validate a user's permission before granting access to the web.

<?php
class AdminPage extends RaxanWebPage {

    protected function _authorize() {
        $level = $this->Raxan->data('user-level');
        if (!$level) $this->redirectTo('login.php'); // redirect to login page
        else if($level=='admin') return true; // tell the framework to continue
        else {
            return false; // display (403 - forbidden access) error page
           // or redirect to an access denied page
           // $this->redirectTo('no-access.php'); // redirect to access denied page
        }
    }
}
?>

The framework will by default return and display a 403 error page. This can be customized by setting the "error.403" config option. See "Error Page settings" in Loading a Custom Config File.


Up Next: Page View Design