用于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元
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号