Provides various official and user-released code examples and code reference. You are welcome to discuss and learn how to optimize ThinkPHP T methods.
ThinkPHP Directory management problems.
When I set an independent template directory, the template directory will become
Template directory/Module name/template topic/template path
However, many CMS files are used to facilitate theme management.
Template directory/template topic/Module name/template path
This directory Mode
So we changed the kernel T method.
/**
* Get Template File Format resources: // module @ topic/controller/Operation
* @ Param string $ template resource address
* @ Param string $ layer view layer (directory) Name
* @ Return string
*/
Function T ($ template = '', $ layer = ''){
// Parse the template resource address
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 ');
// Obtain the topic
$ Theme = substr_count ($ file, '/') <2? C ('default _ THEME '):'';
// Obtain the template path of the current topic
$ Auto = C ('autoload _ NAMESPACE ');
If ($ auto & isset ($ auto [$ extend]) {// scale resources
$ BaseUrl = $ auto [$ extend]. $ module. $ layer .'/';
} Elseif (C ('view _ path ')){
// Change the module view directory
$ BaseUrl = C ('view _ path'). ($ theme? $ Theme .'/':'');
} Elseif (defined ('tmpl _ path ')){
// Specify the global view directory
$ BaseUrl = TMPL_PATH. ($ theme? $ Theme. '/': ''). $ module;
} Else {
$ BaseUrl = APP_PATH. ($ theme? $ Theme. '/': ''). $ module. $ layer .'/';
}
// Analyze template file rules
$ Depr = C ('tmpl _ FILE_DEPR ');
If (''= $ file ){
// If the template file name is empty, locate it according to the default rules.
$ 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: truly free, domain name + VM + enterprise mailbox = 0 RMB