Home > Backend Development > PHP Tutorial > The data between Yii2 two modules need to call each other. How to design to minimize the coupling?

The data between Yii2 two modules need to call each other. How to design to minimize the coupling?

WBOY
Release: 2023-03-02 12:40:01
Original
1901 people have browsed it

There are two modules A and B. Modification of the content in the database of module A must cause the data of module B to be modified together. Module A can also read some data of module B.

How to design to minimize the coupling between modules?

Reply content:

There are two modules A and B. Modification of the content in the database of module A must cause the data of module B to be modified together. Module A can also read some data of module B.

How to design to minimize the coupling between modules?

Regard 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 services layer to handle business logic.
The problem of cross-module calling will not occur. Because the services layer has nothing to do with modules.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template