-1

公式ドキュメントによると、ZF2 モデル ( Zend\Db\TableGateway )で匿名の PHP 関数を使用しています。

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

この無名関数に引数を渡して、where 条件にフィルターを追加するにはどうすればよいですか?

私はそのようなものを使いたいです:

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

ありがとう!

4

1 に答える 1

3

これを試して

$artist = 'John';
$rowset = $artistTable->select(function (Select $select) use ($artist) {
    $select->where(array('artist', $artist));
    $select->order('name ASC');
});
于 2012-11-19T10:51:34.040 に答える