0

Zend Framework 2 文档Zend\Db\TableGateway\TableGateway说:

[Zend\Db\TableGateway\TableGateway] 构造函数可以采用3 种不同形式的特征:作为单个特征对象、作为FeatureSet 对象或作为特征对象数组

TableGateway构造函数实际上检查类型。

因此,TableGateway构造函数的第四个参数需要兼容Feature\AbstractFeature或兼容对象Feature\FeatureSet数组。Feature\AbstractFeature

入门教程的模型部分中,创建了一个类型的对象,TableGateway并获得Zend\Db\ResultSet\ResultSet第四个参数:

class Module
{
    // getAutoloaderConfig() and getConfig() methods here

    // Add this method:
    public function getServiceConfig()
    {
        return array(
            'factories' => array(
                ...
                'AlbumTableGateway' => function ($sm) {
                    $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                    $resultSetPrototype = new ResultSet();
                    $resultSetPrototype->setArrayObjectPrototype(new Album());
                    return new TableGateway('album', $dbAdapter, null, $resultSetPrototype);
                },
            ),
        );
    }
}

ResultSet不是一个instanceof AbstractFeature。但它有效。

它是如何工作的?

4

1 回答 1

1

第三个参数$feature,见TableGateway#31

第四个参数需要兼容ResultSetInterface

于 2013-03-22T17:09:26.323 回答