Architecture Overview

ThinkPHP5.0Based applications MVC(Model - View - Controller) organized manner.

MVC is a design pattern, the input, processing and output makes it mandatory application separately. Using the MVC application is divided into three core components: the model (M), a view (V), the controller (C), their respective own processing tasks.

URL Access 5.0 by routing decisions, routing or close the case if no matching routing is based on:

http://serverName/index.php(或者其它应用入口文件)/模块/控制器/操作/参数/值…

Here are some concepts necessary to understand to do next, may often be referred to in the following pages.

Entry file

PHP files requested by the user, is responsible for handling a request (note, not necessarily the URL request) life cycle, is the most common entry documents index.php, sometimes for some special needs while adding new import documents, such as to the background a file entry module separately provided admin.phpor a controller program entry thinkbelongs entry file.

application

Application ThinkPHPis an object management system architecture and life cycle, by the system  \think\Appto complete the class, applications are often called and executed at the entrance file, with the same application directory ( APP_PATH) application we believe is the same application, but an application There may be multiple entry file.

Application has its own separate profiles, public (function) files.

Module

A typical application is comprised of multiple modules. These modules are usually in a subdirectory of the application directory, and each module has its own separate configuration files, documents and public library file.

5.0 supports a single module architecture design, if you apply the following only one module, then this module subdirectories can be omitted, and modify the application configuration file:

'app_multi_module' =>	false, 

Controller

Each module has a separate MVClibrary and configuration files, a module under multiple controllers responsible for responding to requests, and each controller is actually a separate controller class.

The controller is responsible for receiving the request and calls the process related to the model, and finally output through the view. Strictly speaking, the controller should not be too much involved in the business logic processing.

In fact, the controller 5.0 can be skipped, we can directly request to schedule a model or other classes processed by the route.

5.0 controller class more flexible, may not need to inherit any base class library.

A typical Indexcontroller class is as follows:

namespace app\index\controller;

class Index 
{
    public function index() { return 'hello,thinkphp!'; } } 

operating

The controller contains a plurality of operation (method), a method of operation is the minimum unit of access URL.

The following is a typical Indexmethod of operation defined controller contains two methods of operation:

namespace app\index\controller;

class Index 
{
    public function index() { return 'index'; } public function hello($name) { return 'Hello,'.$name; } } 

The method of operation may not use any parameters, if the definition of a non-optional parameters, the parameter to be passed by a user request, if the request is a URL, it is usually $_GETor $_POSTmode pass.

model

Model classes is typically done actual business logic and data encapsulation, and formats and returns the data independent.

When model classes do not have to access the database, but also in the 5.0 architecture design, only the actual database queries, will be connected to the database, the connection is truly inert.
ThinkPHP model layer supports multi-layer design, you can make more refined design and the division of the model layer, for example, the model layer is divided into logical layer / server layer / event layer, and so on.

view

It returns the class model controller calls through the view into an output data in different formats. View according to different needs, to decide to call a template engine parses the content output or direct output.

A view typically have a series of template files corresponding to different methods of operation and control, and supports dynamic setting template directory.

drive

Many of the components of the system are used driven design, which can be more flexible expansion, the default position of the drive type the following into the core library catalog, you can redefine the position of the drive namespace file to change the drive's library.

behavior

Behavior (Behavior) in a predefined position of the application executing some operations. Similar to the AOPconcept of "aspect" of programming, bind to a particular section related behavior has become a kind AOPof programming ideas. Therefore, the behavior is usually related to a location and execution time depends on the behavior which is bound to the position.

To perform a behavior, you must first conduct a listener in your application, for example:

// 在app_init位置侦听行为
\think\Hook::listen('app_init'); 

Then somewhere behavioral binding:

// 绑定行为到app_init位置
\think\Hook::add('app_init','\app\index\behavior\Test'); 

If you bind a position on a number of acts, executed in the order binding, except when interrupted.

Namespaces

ThinkPHP5Using PHPnamespace library design and planning documents, and in line with PSR-4the automatic load specification.

Guess you like

Origin www.cnblogs.com/furuihua/p/11543068.html