可写在公共继承类,例如adminbasecontroller.class.php 用于覆盖 controller的display() 方法 final protected function display($templatefile='',$charset='',$contenttype='',$content='',$prefix=''){
if(empty($templatefile)) $templatefile=action_name;
if(is_ajax){
c('show_page_trace',false);
//获取指定继承块模板
$block=i('block','');
if(!empty($block)){
//获取模板文件路径
$tpl_file=$this->view->parsetemplate($templatefile);
//获取模板文件内容
$tpl_content=file_get_contents($tpl_file);
//匹配指定block内容
$tpl_find=preg_match('/(.*?)/is',$tpl_content,$tpl_block);
if($tpl_find){
//编译指定block内容
$tpl_html=$this->view->fetch($templatefile,$tpl_block[1]);
$this->ajaxreturn($tpl_html);
}
}
$content = $this->view->fetch($templatefile);
$this->ajaxreturn($content);
}else{
$this->view->display($templatefile);
}
}by:悠悠山雨
ad:真正免费,域名+虚机+企业邮箱=0元
