Various misunderstandings in the form of MVC Architecture in PHP website

Source: Internet
Author: User
Tags php website subdomain
Various misconceptions in the MVC Architecture model of PHP website

??? The MVC architecture pattern is no longer a new technology, it is no longer a term. However, if you can take a look at the internal open source PHP development framework, or the domestic PHP open source software. It is not hard to see that many of these codes are more of a parody than MVC. A lot of MVC is for MVC. Or, only some of the features of MVC are available. Rather than MVC in the real sense. Many of these reasons, of course, are software developers who do not understand design patterns and do not understand the fundamental purpose of MVC.
??? So let's make it clear what the fundamental purpose of MVC is:
??? 1, Division of labor: the use of MVC can be database development, program business Logic Development, page development separate.
??? ? Most people say that the benefits of MVC are limited to this point. That MVC is nothing more than a big team player. It's a big mistake, actually.
??? 2, loose coupling. If you do not understand the design pattern, it is not known what is the meaning of loose coupling. Of course, you can simply explain:
??? ? We divide the module into the database abstraction layer, the data operation layer, and the business logic layer. This is the simplest business architecture. What are the benefits of such separation?
??? ? The database abstraction layer typically supports multiple databases. The purpose of this is to allow your application to quickly replace the database. It also makes it easy for your app to interact with other types of databases.
??? ? At the same time, more powerful, there will be a chain manager, so that the large site of the sub-Library operation, table operation support.
??? ? In general, 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).
??? ? But besides Orm,crud, there are other queries. MVC still requires that it be written into a specialized data manipulation module.
??? Why do you do this? This is loosely coupled. When a part is changed, the other part is not affected.
??? Imagine that if you mix the data modules with the business modules, if you change the database one day, you're going to have to modify the code in the large module section. However, the data module is independent, as long as the Data Module section of the SQL statement can be modified.
??? ? For the view part, the same is true. Because, originally is to the PC browser with, if which day to add the mobile phone page, then as long as the addition can be, the other can be shared, but if not separate, you have to re-do a set.
??? From this point of view, it is said that PHP is not suitable for the use of frameworks, in fact, no framework, many are not feasible.
??? ? You can see the goal: This is achieved, as long as the problem changes one place. Instead of modifying multiple places.
??? 3, sharing and centralized processing. Controller is a component in a program process that completely processes the process in an object-oriented manner. We should be able to remember that the most common PHP program is written, the page header contains the session module, and then the access control. However, if you want to increase the host name, sub-domain control, then each of the included pages, you should add the inclusion again. Or add an include file to the session module, or to the access control module. As a result, the procedural logic becomes quite chaotic. If there is an error and jump, then it is bound to appear in the page does not need to jump to jump.
??? The purpose of the controller is to have the page request finally reach the desired page. and is based on an object-oriented process.
??? Usually: Controller, must have the host, subdomain, Ip,url,acl route detection. Because now a website, simultaneously has the browser and the handset, therefore, also must have the useragent detection. The controller can most easily map a request to a method (event) of a module class.
??? 4, completely object-oriented, MVC program, most only one client request Portal--bootstrap, the application is often based on this file for configuration or modification. All the others are class. This is the implementation of client-to-server event mapping. The purpose of this is to standardize the application process into a fully object-oriented process. Ensure the readability of the program, thus ensuring the independence of the programmer.
??? 5, the current popular open API, if it is a good MVC architecture, open API as long as the direct call data Operation layer interface can be achieved, which also greatly saves the development of the program, while increasing the code of common and centralized processing capacity. This is achieved, as long as there is a problem to modify one place.
??? 6, view problems: Because the requirements of the interface is diverse, constantly changing, often for the web mode of enterprise applications show such a change. For now, sadly, PHP still doesn't have a similar view mode as. NET, or Flex. Only Java, with TYPSTRAY,JFS-oriented view mode for parts, PHP is currently not available with mature open source products. Although, Smarty copied the struts,phpfaces copied JFS, but in essence, there is no full body full use of the advantages of PHP language. Phpfaces is no longer a nobody, almost no one in the domestic use. The impact of flax Ria, and the new RIA technology brought by the JS framework, have not been combined with back-end PHP. JSP backward, like PHP is also backward. People need new sources of open source. Of course, phpfaces can be said to be a pioneer in this respect, because it is a library of components created based on dojo.
??? 7, plug-in technology: a good development framework. All extensions should be done by the plug-in side. But how many frameworks support plugins now? The official Zend can be said to be Daquan, rather than plug-in configuration, which is purely technical misleading. Of course, the best, the most plug-in, it is symfony. The Symfony ORM is still using propel, not using the latest Drysql technology. In terms of plug-ins, in many cases limited the application of software, promotion and development, such as the famous WordPress, provides the perfect application plug-in, but the underlying development framework is extremely chaotic. The simplest, only for MySQL database, if you want to use Oracle, then your nightmare began. Therefore, a good framework should support plug-ins at any level. Plug-ins can be divided into: database-driven plug-ins, data module plug-ins, cache driver plug-ins, graphic library plug-ins and other functional class plug-ins, as well as application-class plug-ins. Now, there is no plug-in technology, there is no success to say. Also only support plug-ins, can achieve unlimited expansion, universality is not empty words. However, from the domestic industry forum, there is no specific discussion of plug-in interface implementation technology related topics, high places cold!!
??? 8, the framework of development frameworks: a Web application architecture, its core should be a good development framework, this framework, must have the core is: The App object, a portal file for all transactions to complete the aggregation class, AutoLoader loader, uxconfig configuration file Read, Uxlocale localization management, model models, view view, controller controllers (host, subdomain, uri,ua,ip,acl all need support), Exception Errorhandle error and exception management, Security Security Management (Validator data validation, filter data filter) state management (Session sessions management, cache cache management). Then there is the basic class library that the application must have, where the database is ranked first. Architecture so put the database into the class library instead of the kernel, mainly two aspects, one, let the user have the choice, the user can choose to use the framework itself, you can also go to choose Adodb,doctrine,peopel and other third-party. Second, the size of the site changes, the database level changes are the fastest. But how many development frameworks now have such a canonical architecture?
??? As a result, we have found that the various misconceptions in the MVC architecture model come from two aspects:
??? One is: People's awareness of the cause. The technical backwardness of PHP development team, poor quality is a major reason. The lack of understanding of the software architecture, especially the object-oriented, design patterns do not understand the MVC in depth.
??? This has something to do with PHP's own development, which was not supported by object-oriented before PHP4. PHP is easy to attract a large number of users. But once used for large-scale website development, for this suspicion JSP annoying lock of people, nightmare began.
??? The second is: the development framework of PHP and open source technology is closely related, the development framework for MVC does not provide good enough MVC architecture support, and there is not good enough open source components, so that people can not further understand MVC. Like, you use PHP's ADODB, but it doesn't require you to separate the data modules from the business modules in the program. This is the architect's responsibility. However, how many network application architects are there in the PHP industry in China? For example, the agile of Shanghai activities, a large company in Hangzhou, a foreign CTO of a large speaker of PHP does not need a framework, and so on, this can not but reflect the domestic technology behind the PHP industry. The reality is so cruel. Only face the current situation of the software industry.
???
???

?

???

1/F 115300111 2011-03-20

Yes, very agreeable.

2/F yuhao_1202 2011-03-27

Not bad. Identity.

  • 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.