Mistakes in the MVC architecture of PHP websites

Source: Internet
Author: User
Tags php software subdomain subdomain name
Are there any mistakes in the MVC architecture of PHP websites ??? The MVC architecture model is no longer a new technology or a new term. However, if you can take a rough look at the internal open source PHP development framework, or the domestic open source PHP software. It is not hard to find that many of the code here is not so much about MVC, it is better to call it an effective solution. Most of them are MVC for MVC. Or, only some MVC functions are provided. various misunderstandings in the MVC architecture pattern of PHP websites

??? The MVC architecture model is no longer a new technology or a new term. However, if you can take a rough look at the internal open source PHP development framework, or the domestic open source PHP software. It is not hard to find that many of the code here is not so much about MVC, it is better to call it an effective solution. Most of them are MVC for MVC. Alternatively, only some MVC functions are provided. Instead of the true MVC. There are many reasons for this, of course, software developers do not understand the design pattern and the fundamental purpose of MVC.
??? Therefore, let's first clarify the fundamental objectives of MVC:
??? 1. division of labor: MVC can be used to separate database development, program business logic development, and page development.
??? ? Most people talk about the benefits of MVC. It is believed that MVC is more conducive to large-scale team cooperation. It is actually a big mistake.
??? 2. Loose coupling. If you do not know the design mode, you do not know what loose coupling means. Of course, you can briefly describe:
??? ? We divide the module into the database abstraction layer, data operation layer, and business logic layer. This is the simplest business architecture. What are the benefits of separation?
??? ? The database abstraction layer generally supports multiple databases. In this way, your application can quickly replace the database. It is also convenient for your applications to interact with other types of databases.
??? ? In addition, a more powerful Link Manager is available to support database and table sharding operations on large websites.
??? ? Generally, the database abstraction layer can generate a static ORM layer through the wizard, or directly provide a dynamic ORM layer (this is the latest DRYSQL mode ).
??? ? However, apart from ORM and CRUD, there are other queries. MVC still requires writing it into a dedicated data operation module.
??? ? Why? This is loose coupling. If some changes are made, the other changes are not affected.
??? ? Imagine if we mix the data module with the business module, if we change the database one day, you need to modify the code of the huge module. However, if the data module is independent, you only need to modify the SQL statements of the data module.
??? ? The view is actually the same. This is because it is intended for PC Browsers. if you want to add a mobile phone page on any day, you only need to add the page. other pages can be shared, but if they are not separated, you have to make a new set.
??? ? From this point of view, some people say that PHP is not suitable for the use of frameworks. In fact, many of them do not work.
??? ? It can be seen that its goal is to achieve this. if there is a problem, you only need to modify it. Instead of modifying multiple locations.
??? 3. Sharing and centralized processing. A controller is a component in a program flow completely designed in an object-oriented manner. We should remember that the most common PHP program is written. the page header contains the SESSION module, followed by access control. If you want to add control over the host name and sub-domain name, the inclusion of each contained page will be added again. You can also add an inclusion file to the SESSION module or the access control module. As a result, the program logic becomes quite messy. If an error or jump occurs, it is bound to jump to or from a page that does not need to be loaded.
??? The purpose of the controller is to make the page request reach the desired page. It is also based on object-oriented processes.
??? Generally: the controller must have route detection for Host, SubDomain, IP, URL, and ACL. Because a website now has both browsers and mobile phones, UserAgent detection is required. The controller must be able to map a request to a method (event) of a module class most conveniently.
??? 4. fully object-oriented, MVC programs, most of which have only one client request entry-bootstrap. applications often configure or modify based on this file. All others are class. That is, event ing from the client to the server is realized. This aims to standardize the application process to a fully object-oriented process. Ensure the readability of the program to ensure the independence from the programmer.
??? 5. Currently, open APIs are popular. if they adopt a good MVC architecture, open APIs can be implemented by directly calling the data operation layer interface, which greatly reduces the development workload of the program, at the same time, the public and centralized processing capabilities of code are added. This is achieved. if there is a problem, you only need to modify it.
??? 6. View problems: as the interface requirements are diverse and constantly changing, enterprise applications in the WEB mode tend to show such changes. Sadly, PHP still does not have a view mode similar to. net or flex. Only JAVA, Typstray, JFS and other component-oriented view modes are available. Currently, PHP is not available as mature open-source products. Although Smarty has copied struts and phpFACES has copied JFS, in essence, it has not fully utilized the advantages of PHP. PhpFACES is even more unattended and almost unattended in China. The impact of flax ria and the new RIA technology brought about by the JS framework cannot be combined with backend PHP. JSP lags behind, and PHP lags behind. People need new open source. Of course, phpFACES can be said to be a pioneer in this regard, because it is a component library created based on DOJO.
??? 7. plug-in technology: a good development framework. All extensions should be completed by plug-ins. But how many frameworks support plug-ins? The official Zend can be said to be full, rather than plug-in configuration, which is purely technical misleading. Of course, the best plug-in is symfony, and symfony's ORM is still using Propel, failing to use the latest DRYSQL technology. In terms of plug-ins, many cases limit the application, promotion, and development of software. for example, the well-known WordPress provides perfect application plug-ins, but the underlying development framework is extremely messy. The simplest way is to use Mysql databases. if you want to use Oracle, your nightmare begins. Therefore, a good framework should support plug-ins at any layer. Plug-ins can be divided into database driver plug-ins, data module plug-ins, cache driver plug-ins, graphic library plug-ins and other functional plug-ins, as well as application plug-ins. In the present era, there is no plug-in technology, and there will be no success. In addition, only plug-ins are supported to achieve unlimited extension, and versatility is not empty talk. However, from the perspective of domestic industry forums, there are no topics dedicated to plug-in interface implementation technology !!
??? 8. Development Framework architecture: the core of a WEB application architecture should be a good development framework. The core of this framework must be the App object, an aggregation class for the entry file to complete all transactions, AutoLoader loader, uxConfig configuration file reading, uxLocale localization management, Model, View, Controller (host, subdomain name, URI, UA, IP, and ACL must be supported), Exception ErrorHandle error and Exception management, Security Management (Validator data verification, Filter data Filter) status management (Session management, cache management ). Then there is the basic class library required by the application, where the database ranks first. In the architecture, the database is put into the class library instead of the kernel. There are two main aspects. one is to give users the right to choose. Users can choose the framework, or select ADODB and DOCTRINE, third-party such as El. Second, database-level changes are the fastest in terms of the scale of websites. But how many development frameworks have such a standard architecture?
??? As a result, we found that the various misunderstandings in the MVC architecture model come from two aspects:
??? One is: people's understanding. The poor quality of the PHP development team is a major essential reason. I do not know about the software architecture, especially the object-oriented and design patterns, so I cannot understand MVC in depth.
??? This is also related to the development of PHP itself. in the past, PHP4 did not support object-oriented. PHP attracts a large number of users easily. But once it is used for large-scale website development, the nightmare begins for those who are so annoying about JSP.
??? The second is that PHP development frameworks are closely related to the development of open-source technologies. The development frameworks do not provide adequate support for MVC architectures and do not have good open-source components, so that people cannot further understand MVC. As if you use the php adodb, but it does not require you to separate the data module from the business module in the program. This is the responsibility of the architect. However, how many network application architects are there in the PHP industry in China? For example, during the agile Shanghai event, a foreign CTO from a large company in Hangzhou spoke about PHP, which does not require a framework at all. cloud computing cannot help but reflect the backward development of PHP technology in China. The reality is so cruel. Only by looking at the current situation of the software industry.
???
???

?

???

On the first floor, 115300111, I agree that yuhao_1202, is good. Yes.

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.