Thinkphp controller display () method implementation principle what is & nbsp; display () in the method, you can automatically search for the template file & nbsp based on the called method name without entering the parameter. how does this happen? How does it obtain the display () in the thinkphp controller of the called method name () principle of implementation
What is the implementation principle of the display () method in the thinkphp controller?
In the display () method, you can automatically search for template files based on the called method name without entering parameters.
How is this implemented? How does it obtain the name of the called method?
We would like to discuss with you how to write code or key methods and ideas that can implement such a function.
------ Solution --------------------
Search for the source code and you will not be able to read it.
PHP code
Define ('Module _ name', self: getModule (C ('Var _ module'); define ('Action _ name', self :: getAction (C ('Var _ action '))); /** + ---------------------- * obtain the actual module name + ------------------------ * @ access private + ------------------------ * @ return string + -------------------- */static private function getModule ($ var) {$ module = (! Empty ($ _ GET [$ var])? $ _ GET [$ var]: C ('default _ module'); if (C ('URL _ CASE_INSENSITIVE ')) {// The URL address is case-insensitive. define ('P _ MODULE_NAME ', strtolower ($ module); // The intelligent identification method index. php/user_type/index/identifies the UserTypeAction module $ module = ucfirst (parse_name (P_MODULE_NAME, 1);} unset ($ _ GET [$ var]); return $ module ;} /** + ---------------------- * get the actual operation name + ---------------------- * @ access private + ------------------------ * @ return string + --- ------------------- */Static private function getAction ($ var) {$ action =! Empty ($ _ POST [$ var])? $ _ POST [$ var]: (! Empty ($ _ GET [$ var])? $ _ GET [$ var]: C ('default _ action'); unset ($ _ POST [$ var], $ _ GET [$ var]); return C ('URL _ CASE_INSENSITIVE ')? Strtolower ($ action): $ action ;}