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

T方法优化

2025/11/22 0:35:24发布15次查看
优化thinkphp的t方法
thinkphp的目录管理有些问题。
当我设置了独立的模板目录以后模板目录会变成
模板目录/模块名称/模板主题/模板路径
然而很多cms为了方便主题管理都是
模板目录/模板主题/模块名称/模板路径
这样的目录模式
所以改了下内核t方法/**
 * 获取模版文件 格式 资源://模块@主题/控制器/操作
 * @param string $template 模版资源地址
 * @param string $layer 视图层(目录)名称
 * @return string
 */
function t($template='',$layer=''){
    // 解析模版资源地址
    if(false === strpos($template,'://')){
        $template   =   'http://'.str_replace(':', '/',$template);
    }
    $info   =   parse_url($template);
    $file   =   $info['host'].(isset($info['path'])?$info['path']:'');
    $module =   isset($info['user'])?$info['user'].'/':module_name.'/';
    $extend =   $info['scheme'];
    $layer  =   $layer?$layer:c('default_v_layer');
    // 获取主题
    $theme  =   substr_count($file,'/')    // 获取当前主题的模版路径
    $auto   =   c('autoload_namespace');
    if($auto && isset($auto[$extend])){ // 扩展资源
        $baseurl    =   $auto[$extend].$module.$layer.'/';
    }elseif(c('view_path')){ 
        // 改变模块视图目录
        $baseurl    =   c('view_path').($theme?$theme.'/':'');
    }elseif(defined('tmpl_path')){ 
        // 指定全局视图目录
        $baseurl    =   tmpl_path.($theme?$theme.'/':'').$module;
    }else{
        $baseurl    =   app_path.($theme?$theme.'/':'').$module.$layer.'/';
    }
    // 分析模板文件规则
    $depr   =   c('tmpl_file_depr');
    if('' == $file) {
        // 如果模板文件名为空 按照默认规则定位
        $file = controller_name . $depr . action_name;
    }elseif(false === strpos($file, '/')){
        $file = controller_name . $depr . $file;
    }elseif('/' != $depr){
        $file   =   substr_count($file,'/')>1 ? substr_replace($file,$depr,strrpos($file,'/'),1) : str_replace('/', $depr, $file);
    }
    return $baseurl.$file.c('tmpl_template_suffix');
}
ad:真正免费,域名+虚机+企业邮箱=0元
该用户其它信息

VIP推荐

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