class Controller
{
public $tpl;
public $controller;
public $body;//右边菜单
public $_route ;
public $html_;
public $tpl_;
/*
* 构造函数
*/
public function __construct()
{
$this->init();
}
/*
* 初始化变量,顶部菜单和模板
*/
protected function init()
{
global $TPL,$route;
$this->tpl = $TPL;
$this->_route = $route;
}
/**
* 模板变量传第
*/
protected function diplayTpl()
{
$this->body || $this->body = $this->_route->getActionName();
$this->tpl->assign("body",$this->body);
/*设置本控制器的模板目录*/
$this->controller ||$this->cOntroller=$this->_route->getControllerName();
$this->tpl->assign("controller",$this->controller);
$this->tpl->display($this->layout);
}
/**
* smarty封装类
* @param string $name
* @param string $value
*/
public function assign($name,$value)
{
$this->tpl->assign($name,$value);
}
/**
* 显示另外的模板
* @param string $name
* @param string $value
*/
protected function displayOther($file)
{
$this->assign("otherTpl",TRUE);
$this->tpl->display($file);
}
/**
* 显示某个MCA的body模板
* 0=>m 1=>c =>a
*/
protected function getMcaBody($array)
{
return 'http://www.cnblogs.com/../'.$array[0].'/body/'.$array[1].'/'.$array[2];
}
/*
* 析构函数,显示页面
*/
protected function __destruct()
{
$this->tpl->_tpl_vars['otherTpl'] || $this->diplayTpl();
}
/**
* 中途退出
*/
protected function _exit($msg = "")
{
$this->assign("otherTpl",TRUE);
die($msg);
}
/**
* 用 $this->html_var=value放法给变量赋值
* 用 $this->tpl_var=value放法给变量赋值
*/
protected function __set($name,$value)
{
if(strtolower(substr($name,0,5)) == "html_" || strtolower(substr($name,0,4)) == "tpl_")
{
$this->assign(substr($name,5),$value);
}
}
}
?>
|