About the use of thinkphp Framework multilayer controllers and multilevel controllers

Source: Internet
Author: User
This article mainly introduces the use of TP (thinkphp) frame multi-layer controller and multi-stage controller, and analyzes the structure, principle and use method of thinkphp frame multi-layer controller and multi-stage controller in the case form, and needs friends to refer to

In this paper, the use of TP (thinkphp) Framework multilayer controller and multilevel controller is described. Share to everyone for your reference, as follows:

The directory structure of the multilayer controller is this:

├─controller Access Controller
│├─usercontroller.class.php
│├─blogcontroller.class.php
│ ...
├─event Event Controller
│├─userevent.class.php
│├─blogevent.class.php
│ ...

Add a multi-tier controller to your app, without adding any parameters, just build the file directly as you would.

Multilayer controller instantiation:

/* * The multilayer controller is instantiated as and when accessing the service of the Controller controllers sibling directory with the D method or a method * Note: The name of the access controller is set through Default_c_layer, the controller is the default, and the access controllers are responsible for the external interactive response , the    other controller layers and external isolation can only be called internally. To define additional controller tiers, you do not necessarily have to inherit the controllers class or its subclasses of the system, often requiring the output template to inherit the controller class. */D (' Admin ', ' Service ');//or a (' User ', ' Event '); A (' Admin/blog ', ' Event ');  Assume that the current module is the Home module//instantiation of the home module of the User event controller $user = new \home\event\userevent ();//instantiation of the Admin module of the Blog event Controller $blog = new \admin\ Event\blogevent ();

The directory structure of the multilevel controller is this:

├─controller Access Controller
│├─user User Rating (group)
││├─usertypecontroller.class.php
││├─userauthcontroller.class.php
│ ...
│├─admin Admin Rating (group)
││├─usercontroller.class.php
││├─configcontroller.class.php
│ ...

Its Access format:

Http://serverName/Home/User/UserType
Http://serverName/Home/Admin/User

Set as a multilevel controller is required to set the configuration parameters, that is, to set the level of the controller hierarchy, such as the level of the 2 directory controller layer, as follows:

' Controller_level '   = 2,

Its command space is this;

<?phpnamespace home\controller\admin;use Think\controller;class Indexcontroller extends Controller {public  function Hello () {    echo ' hello ';  }  Public Function test () {    echo ' Test ';  }}

Multi-level controller instantiation:

can be instantiated directly

Instantiate the User controller of the Home module $user = new \home\controller\user\usertypecontroller ();//Instantiate the Admin module's Blog controller $blog = new \admin\ Controller\admin\usercontroller ();

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

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.