MVC, PHP ++, and PHP

Source: Internet
Author: User
Developers with some experience understand the MVC mode, especially those based on WEB and can use embedded HTML language for development, such as PHP. It is true that PHP is powerful as an embedded scripting language, which has always been recognized by many people by traditional PHP. So that people who have been in contact with and finally gave up PHP in the PHP3 and even in the PHP4 age stay here "> <LINKhref =" http: // www.

Developers with some experience understand the MVC mode, especially those based on WEB and can use embedded HTML language for development, such as PHP. It is true that PHP is powerful as an embedded scripting language, which has always been recognized by many people by traditional PHP. That is why people who have been in contact with and finally gave up PHP in the PHP3 and even in the PHP4 age stay here and think that PHP has no advantages and is too simple. In fact, from a technical point of view, the syntax of a language cannot determine the quality of an application. In many cases, a language is only a tool for implementation, almost all large and medium-sized enterprises should not adopt a single language for development. Each language has its own strengths.

For a long time, PHP has been mixed into many things, including Db, HTML, Controller, Model, and PHP ++. Today, PHP has long been out of the scope of embedding HTML scripting languages. There should be more important things for PHP. Of course, embedding HTML as a script is still a strong point, but it should not be mixed. Let's look at PHP from another perspective. Let's sort out PHP by role and come up with several new terms by the way. PHP-Db is used to deal with databases, PHP-Controler is used to control processes, PHP-Client is used to deal with HTML and other terminal presentations, and so on. This recognition may be clearer.

 


MVC, PHP ++, and PHP

 

I had nothing to worry about over the past few days. I had a new understanding of MVC, and I had a little bit of views, so I made a picture.
 
The biggest result of a long time is whether we need a very large View? In various PHP frameworks, the View language basically uses PHP-Client, such as ZendFramework and QeePHP, and also uses Template labels or template engines. In my opinion, this is actually convenient for developers. In fact, the View can be simplified to extreme. Both Input and Output in the figure involve View. The simplified View does not need to care about the devices, formats, and languages of Input and Output, but only needs to Input data in the correct format (such as JSON and XML ), output data in the specified format (such as JSON and XML ). Similarly, the Output format, method, and means are not what we need to pay attention. For the WEB, data that can be Output can be handed over to ExtJS and PHP (in this case, PHP is a WEB front-end scripting language), and can be handed over to native Javascript for processing. It can even be output to WAP in WML language. That is to say, how to present the View is not the core concern.
But how did we do it? In the Controller, many developers do not pay attention to data format unification and planning, and they are casually thrown to the View. What's more, Controller and View are mixed, with no responsibility or responsibility. What the View does makes the Controller do, while the View is doing the Controller. PHP-Controller should not be integrated into PHP-Client, whether it is a simple website application or an enterprise application. View outputs formatted data, which is conducive to AJAX and WebService. With standardized output, the presentation of views can be independently undertaken by other teams. They love PHP, ExtJS, jQuery, and who they love.

I also understand what a Model is. If you do not understand it correctly, please try again. Model has been occupied by databases for a long time. The Controller has written a lot of content that should be completed by the Model. In a broad sense, the Model is not just a Db. For example, the FCKeditor we use is a Model used to create a visual editor. All models in big aspects can be valued. Let's talk about a small one. For example, the "UserAdd" function in a user system, the user end may be user registration, and the management end may be directly creating a user. If you write directly in the controller, the user end and the management end will repeat the code. This function should be put in the Model for calling. This is called Model. Similar functions are also called business logic. The controller only controls business processes. If the controller is involved in the model, all things will be very swollen, very cumbersome, and will be exhausted.
What is the concept of Cache? A simple example is the product category list. When accessing this list, the core should go to the Cache to check whether the list is to be updated. If not, first update or create a copy in the Cache (this is obviously a small loop or branch judgment ). Then, retrieve the list in the Cache. This removes the need for a large number of database operations, or a large number of Model operations. Of course we can design it to take the initiative to update the Cache if the list is changed. The hit rate is much higher. The efficiency will be improved a lot. Many people think that generating static HTML scripts is the whole Cache, but it is only a small Cache application, which is commonly used in the template engine. If you want to open the Cache, the Cache has no direct relationship with the View. Cache can be used in View, or Controller or Model.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.