Home Backend Development PHP Tutorial thinkpade400578mdc ThinkPHP adopts module and operation analysis

thinkpade400578mdc ThinkPHP adopts module and operation analysis

Jul 29, 2016 am 08:44 AM

Any WEB behavior can be considered as an operation of a module, and the system will analyze the module and operation to be performed based on the current URL. This analysis work is implemented by the URL scheduler, and the official built-in Dispatcher class completes the scheduling. In the Dispatcher scheduler, the project (appName), module (moduleName) and operation (actionName) that currently need to be executed will be obtained according to
http://servername/appName/moduleName/actionName/params
. In some cases, appName is not required (usually the homepage of the website, because the project name can be specified in the entry file, in which case appName will be replaced by the entry file). In more complex situations, grouping (groupName) may also appear.
Each module is an Action file, similar to what we usually call a controller. The system will automatically look for related classes under the Action directory of the project class library. If not found, it will locate the empty module, otherwise an exception will be thrown.
The actionName operation is to first determine whether there is a public method of the Action class. If it does not exist, it will continue to look for the method in the parent class. If it still does not exist, it will look for whether there is an automatically matching template file. If a template file exists, the template output will be 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, it does not need to define a model class, but it must define an Action controller. The definition of the Action controller is very simple, just inherit the Action basic class, for example: microfiber cloth

Copy the code The code is as follows:


class UserAction extends Action{
}


If we want to execute the following The URL
http://servername/index.php/User/add
You just need to add an add method, for example
Collapse PHP Code copy the content to the clipboard

Copy the code The code is as follows:


class UserAction extends Action{
// Define an add operation method. Note that the operation method does not require any parameters
Public function add(){
// Logic implementation of the add operation method
// …… bath rug
$this-&gt ;display(); // Output template page
}
}


The operation method must be defined as Public type, otherwise an error will be reported. And be careful not to duplicate the naming of the operation method with the method of the built-in Action class. The system will automatically locate the template file for the current operation, and the default template file should be located in TpldefaultUseradd.html under the project directory.

The above introduces the module and operation analysis of thinkpade400578mdc ThinkPHP, including the content of thinkpade400578mdc. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

Hot Article

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Working with Flash Session Data in Laravel

6 Extra Skills Every PHP Developer Should Have 6 Extra Skills Every PHP Developer Should Have Feb 28, 2025 am 10:52 AM

6 Extra Skills Every PHP Developer Should Have

Understand Arrays in PHP Understand Arrays in PHP Feb 28, 2025 am 10:53 AM

Understand Arrays in PHP

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Simplified HTTP Response Mocking in Laravel Tests

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

Build a React App With a Laravel Back End: Part 2, React

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

12 Best PHP Chat Scripts on CodeCanyon

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

See all articles