用什么也不用模板引擎。
比如这样:
view.class.phpclass view { private $_val = array();
public function __construct() {
//
}
public function render($filename,$return=false) {
$filepath = APP_PATH."/template/{$filename}.html";
if (!is_file($filepath)) {
throw new Exception("指定的模板文件{$filename}不存在");
}
ob_start();
include_once $filepath;
$content = ob_get_contents();
ob_end_clean();
// 去除空格和换行
$content = str_replace(PHP_EOL,NULL,$content);
$content = preg_replace(array("/>\s+(\s+\n|\r)/Um"),array('>'),$content);
if ($return) {
return $content;
}
echo $content;
}
public function assgin($key,$val) {
$this->_val[$key] = $val;
}
public function __set($key,$val) {
$this->assign($key,$val);
}
public function __get($key) {
return $this->_val[$key];
}
xxxx.php:
<?phpinclude 'view.class.php';$view = new view();$view->assign('key','val');
$view->render('name');
name.html