albert
albert

Reputation: 1816

zf2 : select columns dont work on tablegateway

I created the method 'fetchAll()' in my model in this way

public function fetchAll(){

    $resultSet = $this->tableGateway->select( function (Select $select) {

        $select->columns(array('my_alias'=>'my_field'));

    });

    return $resultSet;

}

so, i get the results in controller

...

$items = $this->getMyTable()->fetchAll();

...

and i sendo to my action

...

foreach( $items => $item ){ print $item->my_alias; } 

...

but '$item->my_alias' is not defined. Without 'columns' method, its work. Whats wrong ?

Upvotes: 1

Views: 1076

Answers (1)

Akhil Sidharth
Akhil Sidharth

Reputation: 746

try this

public function fetchAll(){

    $select = new Select();
    $select->from('table');
    $select->columns(array('my_alias' => 'my_field'));
    $resultSet = $this->tableGateway->selectWith($select);
    return $resultSet;
}

Upvotes: 2

Related Questions