From the total ignorance of the MVC pattern to the slow to understand and write the so-so-so MVC pattern of small programs, the process is extremely egg pain. I want to touch a completely unfamiliar thing, it is probably the feeling of it.
At the very beginning, we looked at a variety of blog Wikipedia, looking at the definition of MVC, the role of MVC. Model is the part of the application that is used to process the logic of the data in the program, which is usually responsible for accessing the data in the database; View is the part of the application that handles the display of the data, the view is created from the Model library, and the controller is the part of the application that handles user interaction. Typically, the controller is responsible for reading data from the view, controlling user input, and sending data to the model, simply by saying that the MVC pattern is to get the business logic and view parts out of the way, leaving the foreground and background of a program separate, which makes it easier for developers to write their own code.
But for a novice, such a description is abstract, there is a sense of indefinitely. Bite the bullet and start writing a small program with an immature idea. However, it failed, and the view part did what the model should do, but the controller was not complete. In addition, file naming, file classification, variables, method naming problems are not uncommon in the program. Through the teacher pointed out these questions, my idea also followed 1.1 points to be corrected.
Then I started looking for an MVC instance on the Internet, maybe it was a very simple example, but it took me a lot of time to understand it, and here's how I understand the MVC process through an example:
By trying to understand the reference instance, I have greatly improved my understanding of the MVC pattern and transformed my own small program. Compared to the last time, the hierarchy is clear, but the code is cumbersome, the structure came out, but the task of the view, the task of the controller is silly. So, I need to refactor the program.
However, I had a big problem and I didn't know how to do it. I think because, this whole idea is not mine, but I imitate the example. So I began to look closely at the definition of MVC, the pros and cons. I think we should master it more to perfect this program. Based on my own thinking, and an example of understanding, I have some of my own unique ideas:
So I started refactoring my work. The controller's role is more obvious, and the index entry is more concise. The data stream becomes Index->controller->model. It's a step closer to the so-so-so MVC pattern. Master explained the next task, consider the extensibility, add modify delete operation.
However, I have never considered the extensibility, the individual modification is easy to delete, but if you want to put him into this non-expansion of the program, but it seems very troublesome. By myself a little bit of thinking, I began to modify the program, the first is to modify the page to add, and then modify the processing of the addition, and finally the processing results returned. It's done. However, the program is a bit unsightly. And it's not going to run on a standard server.
There are a few reasons why you can't get away with this:
Do not understand the use of &, so that the reference to misuse of instances, resulting in procedural errors;
The use of the __autoload () Magic function is not familiar, and does not know its scope, and causes the program to go wrong.
In addition, the program is too cluttered and is required to be rewritten. Moreover, the master told me that the view work could be simpler or even static, and that the controller should be more of a function of the brain. Another day, thinking of the teacher, I continued to look at the definition. M V C! I seem to have a little new understanding:
Every time a rewrite, there is a little new idea, but these ideas do not know is right and wrong, but both right and wrong, this is the result of thinking alone. I think in the implementation of MVC This module, I learned not only the understanding of MVC, but from the mistakes to understand that learning needs to follow the progressive, based on the foundation of the knowledge that they have not mastered, do not mess with. Verification, the function of practice, is the most comfortable function of their own.
I think this can not be the final understanding, I hope that the future process more and more mature.
Complete the process and harvesting of the simple MVC pattern