eXtension Templates for PHP (XTP for short)
WebControlX class - form data, redirecting and similar
To facilitate access to form data, query string, and so on WebControlX class has protected property Request with few useful properties (Please note that property Request also acts as associative array itself, performing search for variable in the following order: QueryString, Form, Cookies):
- QueryString - case insensitive associative array with variables from query string
- Form - case insensitive associative array with form variables
- Files - case insensitive associative array with posted files;
every file is object with following properties/methods
- ContentLength - length of uploaded file
- ContentType - MIME type of uploaded file
- FileName - Name of file on client computer (can be full path or just filename)
- _Path - Path of temporary file on server. You do not need to manually erase this file, object's destructor will take care of that.
- GetInputStream() - Returns content of uploaded file
- Cookies - case insensitive associative array with variables from cookie
- ServerVariables - case insensitive associative array with server variables
In order to facilitate access to session class WebControlX has protected property Session which acts as case insensitive associative array with session data. This property has additional methods Clear (to clear all session data) and Remove (to remove single piece of data from session).
For manipulating user response class WebControlX has protected property Response with method Redirect (for redirecting user to some other location); this method causes current page execution to stop.
Simple example to illustrate usage of all this:
class Index extends WebControlX {
public $Content;
public function PreRender() {
// if user is logged in then show him/her appropriate page,
// otherwise ask for credentials
if (self::$Session['user'])
$this->Content = WebControlX::LoadControl('Controls/user_page.phpx');
else
$this->Content = WebControlX::LoadControl('Controls/login_page.phpx');
// Button logout depressed - clear session data and transfer her/him home
if (self::$Request['logout']) {
self::$Session->Remove('user');
self::$Response->Redirect('index.php');
}
}
}
| « Previous WebControlX - base class | Next » Builtin controls |
