Allow TP to support local controller hierarchical Configuration

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn about the current TP framework. You can set the Controller level of a MODULE, however, I only need to layer some controllers. The following is my solution.
Currently, the TP framework supports setting the Controller hierarchy of a MODULE. However, I only need to layer some controllers. The following is my solution.
Find the file:./ThinkPHP/Library/Think/Dispatcher. class. php line 213rd.
Set If (! Defined ('Bind _ controller') {// get the CONTROLLER
If (C ('controller _ level')> 1) {// CONTROLLER LEVEL
$ _ GET [$ varController] = implode ('/', array_slice ($ paths, 0, C ('controller _ level ')));
$ Paths = array_slice ($ paths, C ('controller _ level '));
} Else {
$ _ GET [$ varController] = array_shift ($ paths );
}
}
Modify If (! Defined ('Bind _ controller') {// get the CONTROLLER
// Adds the Controller hierarchy for local settings.
$ PartLevel = C ('controller _ PART_LEVELS. '. MODULE_NAME.'/'. ucfirst (implode ('', array_slice ($ paths, 0, 1 ))));
If ($ partLevel & $ partLevel> 1 ){
$ _ GET [$ varController] = implode ('/', array_slice ($ paths, 0, $ partLevel ));
$ Paths = array_slice ($ paths, $ partLevel );
} Elseif (C ('controller _ level')> 1) {// CONTROLLER LEVEL
$ _ GET [$ varController] = implode ('/', array_slice ($ paths, 0, C ('controller _ level ')));
$ Paths = array_slice ($ paths, C ('controller _ level '));
} Else {
$ _ GET [$ varController] = array_shift ($ paths );
}
}
Add 'CONTROLLER_PART_LEVELS' => array(
'Www/Widget' => '2',
),
You can set a controller level for a single controller.
For example, the above Code sets the Controller level to 2 for the Widget controller of the Www module separately.

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.