The M of PHP MVC should be the business logic method to be called by C, or the method of accessing the database?

Source: Internet
Author: User
Or is the two included here?

Reply content:

Or is the two included here?

Personally feel that if the business is not complex, the business logic written in the model layer, C-level only write simple scheduling ...
Once a lot of code and logic written on the C layer, but the reusability is very poor, such as the foreground and the background to invoke a business logic basically similar, written on the C-layer feel very redundant
If the business is complex, you can separate layers to deal with the logic, and the M layer is responsible for the data-related storage.

Mainly see your business and Code code conventions, there is no fixed use, to be flexible to use.

Individual suggest that each model data models correspond to a specific data table, processing a separate data table business, logic is the implementation of the business, in accordance with the business package, so as to facilitate maintenance.

M is the data model, for C, M is the equivalent of a database of a table, only responsible for accessing data, business logic is fully implemented in C, C tells m what number of stored fields, M is responsible for generating and executing the corresponding SQL statement and then report the results to C.

Both are available. You can write the usual operations around the model as a method of the model class, or they can be written as business logic into the controller's action.

I generally write the operation around a single model of the CRUD module directly into the method, so called in multiple controllers (Controller to be responsible for error prompt output), complex transactions involving more than one model, is completely written in the controller.

The business logic is all on the C tier, and the C layer has too many responsibilities, and the C layer calls M and V specifically.

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