Custom Controller Method in ThinkPHP framework, thinkphp framework

Source: Internet
Author: User

Custom Controller Method in ThinkPHP framework, thinkphp framework
Each module is an Action file. 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 the model class, but you must define the Action controller, which is generally located under the Lib/Action directory of the project.
The definition of the Action controller is very simple. You only need to inherit the Action base class. For example:

  1. Class UserAction extends Action {}
The name of the controller file is UserAction. class. php.
If we want to execute the following URL
Http: // localhost/App/index. php/User/add
You need to add an add operation method, for example
The name of the controller file is UserAction. class. php.
If we want to execute the following URL
Http: // localhost/App/index. php/User/add

You need to add an add operation method, for example

<? Php // user module class UserAction extends Action {// define an add operation method public function add () {// add operation method logic implementation //... $ this-> display (); // output Page Template }}


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 \ User \ add.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.