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 />');
}
}
?>
For example:
<?php
class MainPage extends RaxanWebPage {
protected function _reset() {
if ($this->someProperty == true) {
return false; // tell the framework not to reset page data
}
}
}
?>
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