扫码关注官方订阅号
有A,B两个模块,A模块数据库中内容修改要使B模块的数据跟着一起修改,A模块还可以读取B模块的一些数据。
该如何设计才能最大程度降低模块间的耦合性?
学习是最好的投资!
把Customer当成A,Order当成B,这个例子中就修改了B中的值。$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();
新增一个services层用来处理业务逻辑。就不会出现你这个跨模块调用的问题了。因为services层跟模块无关。
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
把Customer当成A,Order当成B,这个例子中就修改了B中的值。
$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();
新增一个services层用来处理业务逻辑。
就不会出现你这个跨模块调用的问题了。因为services层跟模块无关。