How to develop lightweight MVC standards in php _ PHP Tutorial

Source: Internet
Author: User
How to develop lightweight MVC standards in php. How to develop lightweight MVC standards in php now there are a lot of free open-source php frameworks in MVC. we don't have to develop a lightweight MVC to duplicate the wheel, this article aims to learn how to develop lightweight MVC standards in php.

Now there are a lot of open-source php free frameworks in MVC. We do not need to develop a lightweight MVC to duplicate the wheel. the purpose of this article is to learn about the structure preparation and MVC ideas of MVC, in this way, the open-source MVC framework can be better applied.

Note: The following definitions are narrow and used to limit the problem domains to be resolved. you can also define your own standards. this is not an industry standard.

  (1) lightweight MVC definition:

1. the framework has no intrusion into applications and does not rely on any interface classes.

2. zero frame configuration and zero annotation

3. it is easy to use and easy to understand. it is not RESTful for the time being, so as to avoid complexity.

  (2) lightweight MVC interface:

1. the Controller uses setter to inject request parameters and supports hierarchical injection, such as book. title.

2. the Controller uses getter to supply data to the View. in the View, the corresponding attribute values can be obtained directly, for example, $ {property }.

3. the Controller uses any non-setter and getter functions to process requests.

4. the Controller uses the function return value to control the redirection. only one Controller can be redirected to another Controller. one Controller cannot correspond to two views.

5. the Controller uses setter to automatically assemble Model dependencies, including dependencies between models.

6. Session parameters, such as loginUserId, are also injected to the Controller through setter. if a request parameter is injected with loginUserId, it will also be overwritten by the Session parameter.

7. one-to-one View and Controller are mapped by name and support various View template types, such as JSP, Velocity, FreeMarker, and CommonTemplate.

8. View execution can be performed without a Controller, which is equivalent to implicit Controller.

9. the framework should provide COC interfaces. based on rule conventions, a package name is model, a package name is controller, and a directory is view, such as com. company. module. controller, automatically discovers the module, loads the model in Singleton mode, and loads the controller in prototype mode.

All in all, except setter, getter, and automatic ing rules, there is nothing in the interface.

  (3) lightweight MVC access:

Http: // host name [: Port] [/application name]/module name/controller name/example name .html [? Parameter name = parameter value]

Note: square brackets indicate saving

  (4) lightweight MVC implementation:

All implementations that comply with the preceding interfaces are acceptable.

  (5) advantages of lightweight MVC:

The business logic does not depend on any framework. it can adapt to any framework without affecting the business code. when the old framework is eliminated and no one is maintained, you can migrate data to a new and more stable framework in the fastest way.

The ideal is beautiful, and the reality is cruel. the above is purely a personal idea. it is much more difficult in reality, and it is always good with the idea of being beautiful.

Today, MVC's php open-source free framework already exists. We do not need to develop a lightweight MVC to duplicate the wheel. the purpose of this article is to learn...

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.