PHP: MVC

xiaoxiao2021-03-06  38

PHP: MVC

Author: EasyChen Source: Beyond the popular PHP recent design patterns, MVC can be seen everywhere, PHP field is no exception, many forums have started to discuss the use of MVC in PHP. However, how does M, V, and C do in PHP? Is MVC really suitable for PHP? Here, EASY gives some own thinking. The prototype MVC of the MVC is originally existing in the Desktop program, and m means a numerical model, V refers to the user interface, and C is the controller. The purpose of using MVC is to separate the implementation code of M and V, so that the same program can use different forms of expression. For example, a batch of statistics can be expressed by column charts, pie charts, respectively. The purpose of the present is to ensure synchronization of M and V, once m changes, V should be updated synchronously. MVCJAVA in Java introduced MVC into the web field, and on this basis, a system called Model2 is scheduled. Due to the particularity of the Web, the MVC in the MVC and Desktop in Java is not exactly the same. The main reason is that V is not continuous in the web, and the user has access once. V will be regenerated once, so V is always consistent with M, no C is required to control synchronization. So what is C be doing in java? The C in Java is usually used for the steering of the process, and it is the DISPATCH mode, which is no longer C. MVC in PHP is impossible to MVC in the original COPY Java in PHP. The problem is mainly manifested on M, in Java, M is a data model independent of business logic and performance logic, and the server-side cross-page exists, Java Bean is playing this foot. The PHP process does not have a long time to stay in memory, only when the PHP page is executed, and it is over when the page interpretation is completed. In this case, we cannot directly implement M directly. Therefore, all PHP programs claimed to implement the MVC mode can only be implemented by simulation means. The implementation is usually stored in the database or cookie / session before the end of the current page, and the M is rebuilt through the database or cookie / session in the next page. In this way, the bean in Java can be said to be a huge overhead. The simple operation of writing data in memory is now transferred from the server to the client or database, then transfer it back. Instead of using such a big overhead to maintain a data model, then plugging this model back to the database, it is better to update the data inside the database directly as needed. The MVC architecture in PHP can now be represented by the following figure. Then let's see V. Many PHP programs now use some template technology to write "using MVC architectures" in the description. In fact, most PHP template programs are only separated by HTML and PHP, rather than MVC emphasized display logic and business logic separation. A page mixing HTML and PHP can be part of the MVC. How to separate display logic and business logic has no satisfactory solution. I personally compare the implementation of http://www.phpe.net/articles/384.SHTML. As for C, and Java is similar, or it is used as a steering, which is not important in PHP. An ultimate resource M a different distinguishing V can have no C to constitute a so-called MVC in PHP. Based on the above analysis, EASY believes that the original 3-layer architecture of PHP is more efficient than the so-called MVC, and the performance layer in the 3-layer architecture is also solved in the MVC in the MVC. An improved 3-layer architecture is more suitable for PHP than MVC. PS: Some options incorporate business logic into M (http://www.phpe.net/articles/382.shtml), which is actually the idea of ​​MVC.

转载请注明原文地址:https://www.9cbs.com/read-112916.html

New Post(0)