Thinkphp3.2 create a global Controller

Source: Internet
Author: User
How to create a global controller in thinkphp3.2 or a later version so that multiple modules can be used together! How to create a global controller in thinkphp3.2 or a later version so that multiple modules can be used together!

Reply content:

How to create a global controller in thinkphp3.2 or a later version so that multiple modules can be used together!

In fact, it is very simple to create a Controller under the Application/Common/Controller directory to inherit the Controller. The namespace is Common/Controller. The default directory does not exist. You need to manually create

Create a controller
Then other controllers extends will not be generic.

MyAction extends ActionOtherAction extends MyAction

TP3.2 already has a completely face-to-face object. We should use the face-to-face object solution, their inheritance relationship is that the Controller of the public method inherits the custom public Controller> inherits the Controller of the TP.

First, create CommonController. class. php under Home/Controller/to copy the namespace and use of this controller from any Controller.

Then modify it in the control that you need to use the method in this controller (for example, there is HelloController. class. php)

Class HelloController extends Controller {
Public function say (){
Echo "hello ";
}
}

Change

Class HelloController extends CommonController {
Public function test (){
Say ();
}
}

This is OK. Please try it on your phone ...... No typographical layout

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.