Abstract: $_server[' path_info ' strings are segmented according to the configured Url_pathinfo_depr to differentiate the module/controller/method
In the LNMP environment to deploy the TP project, according to the network of a data nginx configuration file modified three parameters: Path_info,script_name,script_filename, the system has been able to run normally. But why not modify other parameters such as Request_uri? Are these parameters not affecting the TP routing strategy? (Note: Request_uri does not index.php this part when accessed by rewrite)
With these questions, I analyzed the TP source code, found in the route parsing this part mainly relies on the $_server[' path_info '] parameters, the other two parameters in other places used, for the moment do not talk! Keep track from ingress files to dispatcher::d Ispatch method
/index.php==>/thinkphp/thinkphp.php==>/thinkphp/library/think/think.clas.php/(Run) ==>ThinkPHP/Library /think/app.class.php (init) ==>
Thinkphp/library/think/dispatcher.class.php (Dispatch)
Here are some key analyses:
/********************* get controller *****************************/define (' __INFO__ ' , Trim ($_server[' path_info '), '/');//!! $_server[' Path_info ' has appeared//url suffix define (' __ext__ ', Strtolower (PathInfo ($_server[' path_info '), pathinfo_extension)) ); $_server[' path_info ' = __info__;if (!defined (' Bind_module ') && (! C (' url_router_on ') | | ! Route::check ())) {if (__info__ && C (' Multi_module ')) {//Get module name $paths = Explode ($depr, __info__, 2); $allowList = C (' module_allow_list '); List of allowed modules $module = preg_replace ('/\. '. __ext__. ' $/i ', ', $paths [0]; if (Empty ($allowList) | | (Is_array ($allowList) && in_array_case ($module, $allowList))) {$_get[$varModule] = $module; !!! Reset $_get[' m ']=module_name $_server[' path_info '] = Isset ($paths [1])? $paths [1]: ';//!!! At this point the $_server[' path_info ' has removed the part where the controller is located}}}/****************** get the controller and action ************************/
$depr= C (' Url_pathinfo_depr ');
$paths= Explode ($depr,Trim$_server[' Path_info '],$depr));
If(!defined (' Bind_controller ')) {Get controller
IfC' Controller_level ') >1){Controller hierarchy
$_get[$varController] = implode (‘/‘,Array_slice ($paths,0,C' Controller_level ')));
$paths= Array_slice ($paths,C' Controller_level '));
}Else{
$_get[$varController] = Array_shift ($paths);//!!! Get controller
}
}
Get action
If(!defined (' Bind_action ')){
$_get[$varAction] = Array_shift ($paths);< Span style= "color: #9876aa;" >< Span style= "color: #cc7832;" >
}
Get controller and operation name
Define' Controller_name ',Defined' Bind_controller ')?Bind_controller: self :: Getcontroller ( $varController , $urlCase )) ;
define ( Action_name ' , defined ( ' bind_action ' )? bind_action : self :: ( $varAction $urlCase ))
thinkphp Routing Source Analysis