T method optimization

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.