正如官方文档所述我在ZF2模型中使用匿名PHP函数(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');
});
如何在此匿名函数中传递参数以在where条件中添加过滤器?
我想使用类似的东西:
$this->select(function (Select $select) {
$select->where(array('artist', $artist));
$select->order('name ASC');
});
谢谢!
答案 0 :(得分:3)
试试这个
$artist = 'John';
$rowset = $artistTable->select(function (Select $select) use ($artist) {
$select->where(array('artist', $artist));
$select->order('name ASC');
});