template

来源:互联网 发布:国际象棋在线对弈软件 编辑:程序博客网 时间:2024/06/06 11:49
class TemplateLoader{    protected $_tplDir = 'templates/';    private $_mapVars = array();    public function __construct($options = array())    {        foreach ($options as $k => $v) {            $attr = '_' . $k;            if (property_exists($this, $attr)) {                $this->$attr = $v;            }        }    }    public function assign($name, $value)    {        $this->_mapVars[$name] = $value;    }    public function display($tpl)    {        extract($this->_mapVars);        include $this->_tplDir . $tpl;    }    public function getDisplay($tpl, $vals = array())    {        extract(array_merge($this->_mapVars, $vals));        // @attention maybe some wrong if already ob_start called before        @ob_start();        include $this->_tplDir . $tpl;        $displayInfo = ob_get_clean();        @ob_end_clean();        return $displayInfo;    }}

0 0
原创粉丝点击