Custom Controller method under thinkphp framework

Source: Internet
Author: User

Each module is an action file, so an important process in application development is to define specific actions for different modules. An application that doesn't need to define a model class when it doesn't need to interact with the database, but must define the action controller, which is typically located under the Lib/action directory of the project.
the definition of the action controller is simple, as long as you inherit the action base class, for example:
      Li class= "L0" style= "padding:0px 5px; margin:0px; border-left-width:1px; Border-left-style:solid; Border-left-color:rgb (209,215,220); line-height:23px; Background-color:rgb (250,250,250) "> 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 action method public         function Add () {            // Implementation of the Add Action method logic            //...            $this->display ();//Output page template        }    }


The action method must be defined as the public type, or an error will occur. Also note that the name of the action method is not duplicated with the method of the built-in action class. The template file for the current operation is automatically positioned, and the default template file should be located under the project directory
tpl\user\add.html

Custom Controller method under thinkphp framework

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.