ThinkPHP uses modules and operations for execution. first, a user's request generates an application instance through the entry file. the application controller (called the core controller) manages the entire user execution process, it is also responsible for module scheduling and Operation execution, and finally destroys the application instance. Any WEB action can be regarded as an operation of a module. The system will analyze the modules and operations to be executed based on the current URL. This analysis is implemented by the URL scheduler, which has the built-in Dispatcher class. In the Dispatcher scheduler
Http: // servername/appName/moduleName/actionName/params
To obtain the current project (appName), module (moduleName), and Operation (actionName) to be executed. in some cases, appName can be unnecessary (usually the homepage of a website, because the project name can be specified in the entry file, in this case, the appName will be replaced by the entry file ). In a more complex scenario, a group (groupName) may also appear ).
Each module is an Action File, similar to the controller we usually call. The system will automatically find the related classes under the Action Directory of the project class library. if not found, the system will locate the empty module, otherwise, an exception is thrown.
The actionName operation is to first determine whether there are public methods of the Action Class. if it does not exist, it will continue to look for methods in the parent class. if it still does not exist, it will look for whether there is a template file that automatically matches. If a template file exists, the template output is rendered directly.
Therefore, an important process in application development is to define specific operations for different modules. If an application does not need to interact with the database, you do not need to define a model class, but you must define an Action controller. The definition of the Action Controller is very simple. you only need to inherit the Action base class, for example, microfiber cloth.
The code is as follows:
Class UserAction extends Action {
}
If we want to execute the following URL
Http: // servername/index. php/User/add
You need to add an add method, for example
Collapse the PHP Code and copy the content to the clipboard.
The code is as follows:
Class UserAction extends Action {
// Define an add operation method. Note that no parameters are required for the operation method.
Public function add (){
// Logical implementation of the add operation method
//...... Bath rug
$ This-> display (); // output template page
}
}
The operation method must be defined as Public; otherwise, an error is returned. Note that the name of the operation method should not be the same as that of the built-in Action class. The system automatically locates the template file for the current operation, and the default template file should be located in Tpl \ default \ User \ add.html under the Project Directory.