Home >PHP Framework >ThinkPHP >what is thinkphp controller
ThinkPHP's controller is a class that accepts user input and calls models and views to complete user needs; the controller layer consists of core controllers and business controllers, responsible for application scheduling control, and business The controller is completed by a user-defined controller class.
The operating environment of this tutorial: Windows 7 system, thinkphp v5.1 version, Dell G3 computer.
ThinkPHP is based on the MVC (Model-View-Controller, Model-View-Controller) pattern, and supports multi-layer (multi-Layer) design.
MVC is a design pattern that enforces separation of application input, processing, and output. Applications using MVC are divided into three core components: model (M), view (V), and controller (C), each of which handles its own tasks.
Controller layer
ThinkPHP's controller is a class.
ThinkPHP’s controller layer consists of a core controller and a business controller. The core controller is completed by the App class inside the system and is responsible for the scheduling control of applications (including modules, controllers and operations), including HTTP requests. Interception and forwarding, loading configuration, etc. The business controller is completed by a user-defined controller class. The implementation principle of multi-layer business controller is similar to the layering of models, such as business controller and event controller:
Controller/UserController //For user business logic control and scheduling
Event/UserEvent //Used for user event response operations
Access controller Home/Controller/UserController.class.php is defined as follows:
namespace Home\Controller; use Think\Controller; class UserController extends Controller{ }
Event controller Home /Event/UserEvent.class.php is defined as follows:
namespace Home\Event; use Think\Controller; class UserEvent extends Controller{ }
UserController is responsible for external interaction response and responds through URL request, such as http://serverName/User/index, while UserEvent is responsible for internal event response and only Can be called internally:
A('User','Event');
The default access controller layer is Controller. We can adjust the settings as follows:
'DEFAULT_C_LAYER' => 'Event', // 默认的控制器层名称改为Event
So it is isolated from the outside.
The division of multi-layer controllers is not mandatory and can be freely layered according to the needs of the application. In the controller layer, you can call the layered model as needed, or you can call different layered views (themes).
In the three layers of MVC, ThinkPHP does not rely on M or V. It can even only have C or only V. This is a very important user experience design in ThinkPHP design. The user only needs to define the view. It can be automatically recognized even without C.
[Related tutorial recommendations: thinkphp framework]
The above is the detailed content of what is thinkphp controller. For more information, please follow other related articles on the PHP Chinese website!