search

Home  >  Q&A  >  body text

php - Yii2 两个模块(module)间的数据需要相互调用,如何设计才能最大程度降低耦合性?

有A,B两个模块,A模块数据库中内容修改要使B模块的数据跟着一起修改,A模块还可以读取B模块的一些数据。

该如何设计才能最大程度降低模块间的耦合性?

PHPzPHPz2896 days ago463

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-10 17:29:51

    把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();

    reply
    0
  • 阿神

    阿神2017-04-10 17:29:51

    新增一个services层用来处理业务逻辑。
    就不会出现你这个跨模块调用的问题了。因为services层跟模块无关。

    reply
    0
  • Cancelreply