这是我的功能,当我调用它时会发生以下错误:
由于此对象是在构造函数中使用表和/或架构创建的,因此它是只读的
public function getImpressionLeft($AvailableCampaigns){
$result = $this->tableGateway->select(function(Select $select) use ($AvailableCampaigns){
$select->from(array('a'=>'CampaignSettings'));
$select->columns(array(
'a.CampaignID',
'MaxImpression'=>new \Zend\Db\Sql\Expression('a.MaxImpression - b.TotalImpression'),
'MaxClick'=> new \Zend\Db\Sql\Expression('a.MaxClick - b.TotalClicks'),
))->join(array('b'=>'ImpressionCount'),'a.CampaignID = b.CampaignID',Select::JOIN_LEFT)
->where(new \Zend\Db\Sql\Predicate\In('a.CampaignID',$AvailableCampaigns));
});
return $result->getDataSource();
}
答案 0 :(得分:0)
你过早关闭你的关闭,我很惊讶你没有得到解析错误。你可能永远不会死于教学。
public function getImpressionLeft($AvailableCampaigns){
$result = $this->tableGateway->select(function(Select $select) use ($AvailableCampaigns){
$select->from(array('a'=>'CampaignSettings'));
$select->columns(array(
'a.CampaignID',
'MaxImpression'=>new \Zend\Db\Sql\Expression('a.MaxImpression - b.TotalImpression'),
'MaxClick'=> new \Zend\Db\Sql\Expression('a.MaxClick - b.TotalClicks'),
))->join(array('b'=>'ImpressionCount','a.CampaignID = b.CampaignID',Select::JOIN_LEFT))
->where(new \Zend\Db\Sql\Predicate\In('a.CampaignID',$AvailableCampaigns));
});
return $result->getDataSource();
}
另一点是$ result是一个ResultSet对象,所以你可以在foreach中迭代它来读取每一行,你可以尝试返回$result
而不是$result->getDataSource();