2012-11-19 3 views
-1

를 사용 ZF2의 조건은 는 공식 문서로서 익명 기능

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

(Zend\Db\TableGateway)

어떻게 필터를 추가하려면이 익명 함수에 인수를 전달하는 내 ZF2 모델에서 익명의 PHP 함수를 사용하고 어디 말 어디서?

그 같은 것을 사용하고 싶습니다 :

$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'); 
}); 
시도