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