优化ThinkPHP的T方法
ThinkPHP的目录管理有些问题。
当我设置了独立的模板目录以后模板目录会变成
模板目录/模块名称/模板主题/模板路径
然而很多CMS为了方便主题管理都是
模板目录/模板主题/模块名称/模板路径
这样的目录模式
所以改了下内核T方法/**<br>
* 获取模版文件 格式 资源://模块@主题/控制器/操作<br>
* @param string $template 模版资源地址<br>
* @param string $layer 视图层(目录)名称<br>
* @return string<br>
*/<br>
function T($template='',$layer=''){<br>
// 解析模版资源地址<br>
if(false === strpos($template,'://')){<br>
$template = 'http://'.str_replace(':', '/',$template);<br>
}<br>
$info = parse_url($template);<br>
$file = $info['host'].(isset($info['path'])?$info['path']:'');<br>
$module = isset($info['user'])?$info['user'].'/':MODULE_NAME.'/';<br>
$extend = $info['scheme'];<br>
$layer = $layer?$layer:C('DEFAULT_V_LAYER');<br>
// 获取主题<br>
$theme = substr_count($file,'/')
// 获取当前主题的模版路径<br>
$auto = C('AUTOLOAD_NAMESPACE');<br>
if($auto && isset($auto[$extend])){ // 扩展资源<br>
$baseUrl = $auto[$extend].$module.$layer.'/';<br>
}elseif(C('VIEW_PATH')){ <br>
// 改变模块视图目录<br>
$baseUrl = C('VIEW_PATH').($theme?$theme.'/':'');<br>
}elseif(defined('TMPL_PATH')){ <br>
// 指定全局视图目录<br>
$baseUrl = TMPL_PATH.($theme?$theme.'/':'').$module;<br>
}else{<br>
$baseUrl = APP_PATH.($theme?$theme.'/':'').$module.$layer.'/';<br>
}<br>
// 分析模板文件规则<br>
$depr = C('TMPL_FILE_DEPR');<br>
if('' == $file) {<br>
// 如果模板文件名为空 按照默认规则定位<br>
$file = CONTROLLER_NAME . $depr . ACTION_NAME;<br>
}elseif(false === strpos($file, '/')){<br>
$file = CONTROLLER_NAME . $depr . $file;<br>
}elseif('/' != $depr){<br>
$file = substr_count($file,'/')>1 ? substr_replace($file,$depr,strrpos($file,'/'),1) : str_replace('/', $depr, $file);<br>
}<br>
return $baseUrl.$file.C('TMPL_TEMPLATE_SUFFIX');<br>
}
AD:真正免费,域名+虚机+企业邮箱=0元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
