【发布时间】:2013-05-23 13:59:12
【问题描述】:
我有一个以前已经有一个简单的 fetchAll() 方法的类。我从 ZF2 教程中得到它,它使用 ResultSet 和 TableGateway。只是现在我希望它接受一个我可以检查的参数,以便如果传递了客户 ID,它只会返回具有该客户 ID 的行。
这个方法是这样的:
public function fetchAll($CCID = null)
{
if($CCID == null){
$resultSet = $this->tableGateway->select();
return $resultSet;
} else {
// Same as above, only where customerId = $CCID
return $resultSet;
}
}
我试过这个(添加使用 Zend\Db\Sql\Sql:
$resultSet = $this->tableGateway->select->where(array('customerId' => $CCID));
这几乎是一个完整的猜测,但我尝试了它,因为它看起来很有意义。在我的模块文件中,TableGateway 工厂如下所示:
'JobsTableGateway' => function($sm){
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Job());
return new TableGateway('runningjobs', $dbAdapter, null, $resultSetPrototype);
},
有没有人知道如何像条件的第一部分一样基本上执行标准的 fetchAll(),除了“where”部分?或者也许有更好的方法?
【问题讨论】:
标签: php jquery database zend-framework2