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;
}
}
template
最新推荐文章于 2022-12-12 10:59:51 发布