Home >php教程 >php手册 >获取模板继承中指定block块的HTML编译代码

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

WBOY
WBOYOriginal
2016-06-07 11:38:201299browse

用于AJAX 获取 模板中需要变动的部分代码
可写在公共继承类,例如AdminBaseController.class.php 用于覆盖 Controller的display() 方法    final protected function display($templateFile='',$charset='',$contentType='',$content='',$prefix=''){<br>         if(empty($templateFile)) $templateFile=ACTION_NAME;<br>         if(IS_AJAX){<br>             C('SHOW_PAGE_TRACE',false);<br>             //获取指定继承块模板<br>             $block=I('block','');<br>             if(!empty($block)){<br>                 //获取模板文件路径<br>                 $tpl_file=$this->view->parseTemplate($templateFile);<br>                 //获取模板文件内容<br>                 $tpl_content=file_get_contents($tpl_file);<br>                 //匹配指定block内容<br>                 $tpl_find=preg_match('/<block>(.*?)/is',$tpl_content,$tpl_block);<br>                 if($tpl_find){<br>                     //编译指定block内容<br>                     $tpl_html=$this->view->fetch($templateFile,$tpl_block[1]);<br>                     $this->ajaxReturn($tpl_html);<br>                 }<br>             }<br> <br>             $content = $this->view->fetch($templateFile);<br>             $this->ajaxReturn($content);<br>         }else{<br>             $this->view->display($templateFile);<br>         }<br>     }</block>BY:悠悠山雨

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn