Thinkphp null operation, empty controller, namespace example explanation
This article introduces the relevant knowledge of "Thinkphp null operation, empty controller, namespace instance explanation". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Null operation
Null operation means that when the system can not find the requested operation method, it will locate the null operation (_ empty) method to execute. Using this mechanism, we can optimize the error page and some URL.
The page appears:
The error message displayed is too detailed and a null operation is performed for the sake of security and optimization of the page.
1. Make an empty () method. Write in the subclass, not in the parent class (recommended)
Function _ empty () {echo "web page does not exist, please check the browser address information!" ;}
two。 Create a template corresponding to this method
Create a new text.html file under view/main
Don't visit randomly.
Note: the null operation method is only valid if your controller class inherits the system's Think\ Controller class, otherwise you need to define _ _ call to implement it.
2. Empty controller
The concept of empty controller means that when the system cannot find the requested controller name, the system will try to locate the empty controller (EmptyController). Using this mechanism, we can customize the error page and optimize the URL.
Home/Controller/EmptyController.class.php