Data between two modules of Yii2 needs to be called each other. how can we minimize coupling?

Source: Internet
Author: User
There are two modules A and B. to modify the content in the database of module A, the data of module B should be modified together. module A can also read some data of module B. How can we minimize the coupling between modules? There are two modules A and B. to modify the content in the database of module A, the data of module B should be modified together. module A can also read some data of module B.

How can we minimize the coupling between modules?

Reply content:

There are two modules A and B. to modify the content in the database of module A, the data of module B should be modified together. module A can also read some data of module B.

How can we minimize the coupling between modules?

Take Customer as A and Order as B. In this example, the value in B is modified.
$ Customer = Customer: findOne (123 );
$ Order = new Order ();
$ Order-> subtotal = 100;
//...

// Setting the attribute that defines the "customer" relation in Order
$ Order-> customer_id = $ customer-> id;
$ Order-> save ();

Add a service layer to process the business logic.
There will be no problem with your cross-module call. Because the services layer has nothing to do with the module.

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.