About the use of multi-layer controllers and multi-level controllers in the thinkPHP framework

不言
Release: 2023-04-01 08:18:01
Original
2563 people have browsed it

This article mainly introduces the use of TP (thinkPHP) framework multi-layer controllers and multi-level controllers, and analyzes the structure, principles and usage of thinkPHP framework multi-layer controllers and multi-level controllers in the form of examples. Friends in need can refer to

This article describes the use of multi-layer controllers and multi-level controllers in the TP (thinkPHP) framework. Share it with everyone for your reference, the details are as follows:

The directory structure of the multi-layer controller is as follows:

├─ Controller Access Controller
│ ├─UserController.class.php
│ ├─BlogController.class.php
│ ...
├─Event Event Controller
│ ├─UserEvent. class.php
│ ├─BlogEvent.class.php
│ ...

Add multi-layer controllers to the App application. No need to add any parameters, just follow the above Just create the file directly.

Multi-level controller instantiation:

/* * 多层控制器实例化 即和访问控制器Controller同级目录的Service时 可用D方法或A方法 * 注:访问控制器的名称是通过DEFAULT_C_LAYER设置的,默认是Controller,访问控制器负责外部交互响应, 其它的控制器层和外部隔离,只能内部调用。定义其他的控制器层,则不一定必须要继承系统的Controller类或其子类,通常需要输出模版的时候才需要继承Controller类。 */ D('Admin', 'Service'); //或者 A('User','Event'); A('Admin/Blog','Event'); //假设当前模块是Home模块 // 实例化Home模块的User事件控制器 $User = new \Home\Event\UserEvent(); // 实例化Admin模块的Blog事件控制器 $Blog = new \Admin\Event\BlogEvent();
Copy after login

And the multi-level controller The directory structure is like this:

├─Controller access controller
│ ├─User User classification (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

Setting up a multi-level controller requires setting configuration parameters, that is, setting the hierarchical level of the controller, for example, setting level 2 The controller layer of the directory is as follows:

'CONTROLLER_LEVEL' => 2,
Copy after login

The command space is like this;


        
Copy after login

Instancing of multi-level controllers:

can be instantiated directly

// 实例化Home模块的User控制器 $User = new \Home\Controller\User\UserTypeController(); // 实例化Admin模块的Blog控制器 $Blog = new \Admin\Controller\Admin\UserController();
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

About the usage of custom configuration and loading of ThinkPHP3.2 framework

##How does thinkPHP framework implement multiple Table query

The above is the detailed content of About the use of multi-layer controllers and multi-level controllers in the thinkPHP framework. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!