【问题标题】:call a Method from One Repository to another Repository Symfony2从一个存储库调用方法到另一个存储库 Symfony2
【发布时间】:2017-11-03 12:14:09
【问题描述】:

您好,我正在使用 symfony2 和 ODM,我想将一个函数从一个存储库调用到另一个存储库以重新使用它。我没有办法直接调用它。

按照我的代码。

//我的LedgerRepository.php

class LedgerRepository extends DocumentRepository
{

public function ProfitLoss(){
//Some re-usable code

  }
 }

//我的BudgetRepository.php

class BudgetRepository extends DocumentRepository
{
 //So here I want to call method ProfitLoss() from LedgerRepository


}

如何实现,请指导。

提前感谢

【问题讨论】:

    标签: mongodb symfony-2.1


    【解决方案1】:

    在这种情况下,好的旧继承可能会派上用场。 LedgerBudget 都处理金融交易。为什么不是这个?:

    class TransactionsRepository extends DocumentRepository
    {
        public function ProfitLoss() {}
    }
    
    class LedgerRepository extends TransactionsRepository {}
    class BudgetRepository extends TransactionsRepository {}
    

    在这种情况下,LedgerBudget 都可以在 TransactionsRepository 中“共享”方法。

    【讨论】:

    • 我通过以下方式做到了这一点:使用 Edu\AccountBundle\Document\BudgetRepository 作为预算;然后调用:Budget::getProfitLossAccountsDetails($dm, $session, $dataPostedToIncomeExpense)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-25
    • 1970-01-01
    • 1970-01-01
    • 2010-10-30
    • 1970-01-01
    • 2012-06-21
    相关资源
    最近更新 更多