0

Here is my function, when I call it the following error occurs:

Since this object was created with a table and/or schema in the constructor, it is read only

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();
}
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Mohd Sadiq
  • 181
  • 1
  • 2
  • 16

1 Answers1

0

You are closing your closure too soon, I'm surprised you didn't get a parse error. You may never get to die instruction.

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();
    }

another point is that $result is a ResultSet object, so you can iterate it in a foreach to read each row, you could try returning $result instead of $result->getDataSource();

SmasherHell
  • 894
  • 8
  • 19
  • thanks for your reply, sorry i post wrong code . i have edited it – Mohd Sadiq Mar 12 '14 at 08:39
  • @SadiqGaur just edited mine too, as the result of TableGateway::select() is a ResultSet – SmasherHell Mar 12 '14 at 11:23
  • not getting any thing no resultset,only the errro is appear "Since this object was created with a table and/or schema in the constructor, it is read only" – Mohd Sadiq Mar 12 '14 at 13:56
  • Actually, there is another post that might help you [TableGateway with multiple FROM tables](http://stackoverflow.com/questions/14354802/tablegateway-with-multiple-from-tables). Basic gateway seems to be bound to one table, the post show you an exemple to exends a new gateway from AbstractTableGateway – SmasherHell Mar 12 '14 at 16:24