What is the logic and service layer in thinkphp for?

Source: Internet
Author: User
Keywords Model
I usually develop only use the model layer, I ask these two layers are dry what use? I spent the relevant content, are directly according to the official manual copy, and did not specifically say clearly, can you give an example to illustrate?

Reply content:

Speaking of my own understanding, the traditional MVC three layer in the face of the system is getting larger and more complex business logic, the beginning appears to be "not enough".
Not enough to do, and then abstract and then layered chant.

The business logic processing part is abstracted out as a layer, above m, C, called Logic.
Abstract as a layer of services that can be used as a public, this layer is not coupled with any layer, but only provides its own services, called service.


Give me a chestnut:
A large website, or now more popular interface, microservices what what,
It's impossible to just send a request, read and write data, return data so simple,
Requests need to be processed after the request is accepted, and data needs to be processed after reading and writing the data.
After all the processing has been done, you'll find it's weird to put it on the C-level. The C layer is getting bloated.
It doesn't feel right to put it on the M layer, The m layer should be dealing with the database., the processing of business logic should not be put here;
On the logic layer is the best, the business changed, C and M layers do not need to change, just need to change the middle of Logic.

What does the Service layer put? That's a lot,
Small to file upload, download, image processing, storage
Big to log, error handling, mail, authorization, queue, scheduled task, payment, verification, encryption, SMS, Balabala, beep, PA pa
We can use them in many places as a service.

Just Jiangzi ~ thought to add, remember to praise.~ Uninvited, no invitation.
Phone simple answer under

It is often sufficient to develop a simple project with MVC layering. As the project grows larger and bigger. A clear architecture is needed to reduce the complexity of the code.
The easiest to think of is 2 points to improve

13-party service. This type of code belongs to the public code. In fact, it has little to do with business logic. such as logs. Mail. SMS.

2 coupling between model and model. Model is usually based on the domain model abstraction later encapsulated by a single-accused class or function set. Many business logic that needs to be combined with multiple model implementations. It can also be put in the model layer or other way in other standalone file implementations. But it's going to be a lot more expensive to maintain. Abstract the logic layer between M and C deals with these in order to facilitate the follow-up service of the invitation
It's useless, I don't know.

Personal understanding: In order to precisely define C-and M-layers, reduce the logic in which the split function introduces other hierarchical concepts
  • Related Article

    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.