2012-11-19 112 views
-1

隨着官方文檔條件ZF2說我用匿名PHP函數在我ZF2模型(Zend\Db\TableGateway凡使用匿名函數

use Zend\Db\TableGateway\TableGateway; 
use Zend\Db\Sql\Select; 
$artistTable = new TableGateway('artist', $adapter); 

// search for at most 2 artists who's name starts with Brit, ascending 
$rowset = $artistTable->select(function (Select $select) { 
     $select->order('name ASC'); 
}); 

如何傳遞參數在這個匿名函數添加一個過濾器在哪裏條件?

我想用類似的東西:

$this->select(function (Select $select) { 
      $select->where(array('artist', $artist)); 
      $select->order('name ASC'); 
}); 

謝謝!

回答

3

試試這個

$artist = 'John'; 
$rowset = $artistTable->select(function (Select $select) use ($artist) { 
    $select->where(array('artist', $artist)); 
    $select->order('name ASC'); 
});