tutorial on using instances of PHP classes

Source: Internet
Author: User
Tags mixed

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);
}
}

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.