Zend 2 TableGateway conundrum? -


i have these 2 pieces of code... in head, identical, 1 works , 1 doesn't. hoping can me figure out.

this code doesn't work. returns entire table, ignoring orderby , limit.

public function getnews($limit = null) {     $select = new select();      $select->order('date desc');     if($limit != null)     {         $select->limit($limit);     }      $result = $this->gateway->select($select);     return $result; } 

this code rearranged use anonymous function , works perfectly.

public function getnews($limit = null) {     $result = $this->gateway->select(         function(select $select) use ($limit)         {             $select->order('date desc');             if($limit != null)             {                 $select->limit($limit);             }         }     );      return $result; } 

any insight appreciated.

the second way how tablegateway::select method meant used. either pass simple array of predicates or closure performs more complex operations on select object.

check out documentation on tablegateway more details.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -