您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

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

2024/6/5 12:25:48发布22次查看
用于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元
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product