When it's time to learn PHP, it's not difficult to find out how to actually do some single function modules. But a system often has a lot of modules tangled together, when we actually develop it, we will find a lot of code redundancy, call up is not convenient. And the more you write the more the more you feel more and more confused, and finally mess.
So, think about whether you can build a way to call these modules on these modules. If you want to implement what function directly call the corresponding module, do not consider the specific implementation.
Therefore, the upper level release instructions, the lower level concrete implementation. This way of thinking is clear, the problem is not so complicated. A clear division of labor is the trend of the times, but also the trend of code.
Patterns and frameworks are such a wisdom.
Now, I began to follow the footsteps of my predecessors and embark on a journey of MVC design patterns, documenting the experiences and experiences of these days.
First of all thanks to the Pengcheng great God's tutorial, the code is from him, I just talk about my own experience.
MVC design Pattern:
M->model V->veiw C->controll
Model is responsible for the processing of data
Here is the simple processing, directly return a string of STR as a data processing it ~
View is responsible for presenting to the client
View received data $data and output to the foreground, in order to be simple, directly echo ~
Controll is responsible for the overall control of model and view behavior.
Controll, generates a model object and calls the method that gets the data to generate the View object and invoke the output data
Everything is ready, only owe call. Next, create a new PHP call Controller Controll's Show method to test:
Operation Result:
At the end of the first phase of the ~MVC is not so mysterious and difficult to understand, step by step slowly untie its veil