The relationship between URL path access and module controller in ThinkPHP is a very important link in ThinkPHP program development. Proficient mastering this technique plays a crucial role in further learning ThinkPHP. The specific analysis is as follows:
Open the controller page:
//Path: admin\Lib\Action\ The admin here is the directory corresponding to the newly created project
We all know that the method in Action defaults to Public attributes, and methods with private attributes cannot be accessed, but methods with private attributes also have their significance.
The meaning of defining a private method is mainly reflected in the fact that you can write a method related to the user module here, but you don’t want the original method to be too bloated. Therefore, we can define a private method to implement it. If the verification specification changes, you only need to change one of the methods. No need to find a lot of code.
The sample code is as follows:
class UserAction extends Action{ function index(){ echo 'This is the homepage'; } function add(){ $this->verify(); echo 'This is how to write data to the database'; } private function verify(){ echo 'This is the way to verify'; } }
..//User/add execution result:
This is the method of verification This is the method of writing data to the database
I hope this article will be helpful to everyone's ThinkPHP programming.