您好,欢迎访问一九零五行业门户网

php类的使用实例教程

php类的使用实例教程
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);
 }
}
?>
其它类似信息

推荐信息