zf2 从一个模型调用另一个模型中的方法

zf2 call a method from a Model in another Model

我在 ZF2 项目中有几个模块。每个模块都有不同的模型 classes 执行不同的所需功能。现在我在第一个模块的模型 class 中有了方法,我想在第二个模块的模型 class 中调用它。有可能这样做吗?如果是,怎么做?

这应该相当简单。首先,您需要在 application.config.php

中包含这两个模块
'modules' => array(
    'Module1',
    'Module2'
)

然后从你的问题中提取一个非常基本的例子:

<?php
namespace Module2\Model;

use Module1\Model\Class1;    

class Class2
{
    public function doSomething()
    {
        $class1 = new Class1();
        $class1->doSomething();
    }
}