In MVC Controller

Controller class

Based on the correlation function, a series of related functions, using a controller class to handle, and each method of the controller, on the right because of a function.

Note: The controller is divided by function.

 

Front-end controller (request dispatcher, entry file)

More listAction () operation How should it be called?

Instantiated and out method can be!

Where is instantiated or call it?

Add a can instantiate and call the controller method of file.

 

Action action distribution parameters: a

How to do a front controller, you can call a different method of action controller class it?

When requested the index.php front controller, passing it a parameter name indicates the current operation to be performed, for example:

Function: game list:

Index.php?a=list

Function: Delete the game:

Index.php?a=remove

Tip: forming a link address, you should determine the good in the HTML code, then there is a default action can be!

Index.php determining a parameter, to perform a corresponding action

 

The controller controller distribution parameters: c

If you need to perform an action in another controller should be processing front controller?

When requested the index.php front controller, passing it the parameters c, it represents the class name of the current controller needs to be performed, such as:

 Game action list:

Index.php?c=Match&a=list

 The team's information actions

Index.php?c=Team&a=info&id=TID

 c, a link in the HTML address, is automatically formed good

 

Use constant parameter storage distribution

Thinking:

In a request cycle, the name of the controller (current controller) requested, and action name (the current action) requested, whether the change happen?

Change will not happen!

 How at the level of syntax, ensure that within the next request cycle, the current controller and the current action does not change?

In a variable, memory is not guaranteed.

You should use the constant, the current storage controller and its current action to ensure

 

Base controller

Increasing the code controller provides the basis for all classes of controllers: Controller

Other controllers, inherited from the base controller

 

Initialization Content-Type of the underlying operating

Controller.class.php

class Controller{

  protected function _initContentType(){

    header('Content-Type:text/html;charset=utf8');

  }

}

transfer:

In the instance of a controller object called in the constructor:

Controller.class.php

public function __construct(){

  $this->_initContentType();

}

note:

Request address (URL) browser are fixed in the form of:

Index.php?c=Controller&a=action&

Called single entry mode

 Any project to provide both functions, are made of a method of a controller class to achieve

Guess you like

Origin www.cnblogs.com/zsyzsyzsyzsyzsy/p/10971503.html