欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

获取模板继承中指定block块的HTML编译代码

程序员文章站 2022-05-27 20:34:20
...
用于AJAX 获取 模板中需要变动的部分代码
可写在公共继承类,例如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元