如何水合包含其他对象的对象

时间:2014-10-01 18:56:22

标签: zend-framework2

如何创建其他实体设置的实体?我使用mapper / hydrator和hydrator srategy就像这个例子。

class AccountMapperFactory implements FactoryInterface
{
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $dbAdapter = $serviceLocator->get('zfcuser_zend_db_adapter');

        $entity = new Account();

        $mapper = new AccountMapper();
        $mapper->setDbAdapter($dbAdapter);

        $hydrator = new AccountHydrator();
        $hydrator->addStrategy('orderId', new OrderStrategy());

        $mapper
            ->setEntityPrototype($entity)
            ->setHydrator($hydrator)
            ->setTableName($mapper->getTableName());

        return $mapper;
    }
} 

然后我可以这样称呼它

$this->AccountMapperFactory()->findById(1);

我使用空订单实体获取帐户实体,如何创建填充对象的方式呢?

谢谢,

1 个答案:

答案 0 :(得分:0)

对于正在寻找答案的人,我发现了这两个参考文献。

retrieving-every-field-of-a-database-row-as-object-in-zend-framework-2

generate-entities-with-mappers