The action layer in Yii, in addition to understanding the decoupling action, so that the code is reused, which part of the role is played in MVC?
Reply content:
The action layer in Yii, in addition to understanding the decoupling action, so that the code is reused, which part of the role is played in MVC?
Yii has not been used, but MVC is basically the path. The action should be the controller, generally speaking the controller is best to do the distribution and output of the request, it is best not to do any processing in action. It can be understood that a project is a restaurant, action is a waiter, his job is to receive the guest's request, and then communicated to the chef, cook the dishes, the waiter returned to the guests, so much. But this will involve problems, such as the guest point is the stew, the waiter should tell the cook a stew, guests want dessert, the waiter should inform the pastry division B. If the restaurant has more than one dish, the waiter has to remember a lot of correspondence, which means that the logic of conveying the request is complex. If the waiter is sick and leave, it is difficult to find someone to replace it, because the job is very complex, which corresponds to our code to modify or add functionality. If our action is very complex, it is very painful to change the code, and it may even be possible to add a little bit of new functionality that will cause the entire program to fail to compile.
So now the big restaurant, the waiter basically is to use a machine to generate orders, and then by the machine to inform each chef. The advantage is that the waiter's work becomes very simple, it is very easy to find a new waiter. This behavior corresponds to the MVC architecture and is also very common, called a delegate. That is, the action receives the request, only needs to do a simple processing, and then delegates to a special model for further request distribution and filtering, the model again to tune the real handler. This model, commissioned for distribution, belongs to the M-layer.
Many of our design patterns are also used in the M layer, such as the distribution of the model to implement a factory mode or strategy mode, and so on, these are in the M layer of processing, action is the C layer, try to keep the action concise. Analogy, as far as possible to let the waiter juvenile business, more energy in the service to customers, action more attention is to do the user interface.
Controller chant.
http://segmentfault.com/blog/trigkit4/1190000002386651
Action method is an action, belonging to the controller;
The most standard MVC model used by the YII framework is that the class that the action belongs to inherits from the controller:
class TracerController extends Controller{ public function actionIndex() { $this->render('index'); }}
Landlord please Baidu: Yii authoritative guide PDF
A very thin booklet that will be very clear about MVC;