tutorial on using instances of PHP classes
<?php
/**
* Class Program for Yinghua05-2
* Designer:songsong
*/
Class Template {
var $tpl _vars;
var $tpl _path;
var $_debug;
/**
* Construct for Template
* PHP5 or Upper version
*/
function __construct () {
$this->template ();
}
/**
* Construct for Template
*
* @return Template
*/
function Template () {
$this->tpl_vars = Array ();
$this->tpl_path = ';
$this->_debug = false;
}
/**
* Set Template path
*
* @param string $path
* @return Boolean
*/
function SetPath ($path) {
if (Is_dir ($path)) {
$path = RTrim ($path, '/'). ' /';
$this->tpl_path = $path;
return true;
} else {
if ($this->_debug) {
$this->_debug (' template path is not exists. ');
}
return false;
}
}
/**
* Enter description here ...
*
* @param mixed $var
* @param mixed $val
*/
function assign ($var, $val) {
if (Isset ($var) && Is_array ($var)) {
$this->tpl_vars = $var;
else if (isset ($var) && $var!= ') {
$this->tpl_vars[$var] = $val;
} else {
if ($this->_debug = = True) {
$this->_debug (' Set variable error. ');
}
return false;
}
}
/**
* Display template file
*
* @param String $file _name
*/
function display ($file _name) {
Ob_start ();
Extract ($this->tpl_vars);
$include _flie = $this->tpl_path. $file _name;
if (!file_exists ($include _flie)) {
if ($this->_debug)
$this->_debug (' Template file '. $include _flie. ' is not exists. ');
Else
Exit (' Template error, please check it. ');
}
Include ($include _flie);
$content = Ob_get_contents ();
Ob_end_clean ();
Echo $content;
}
/**
* debuging
*
*/
function _debug ($msg = ' ") {
Die (' Error: '. $msg);
}
}
?>