createQueryBuilder警告未定义变量:list

时间:2017-02-08 10:00:09

标签: arrays symfony doctrine-orm query-builder

当我运行createQueryBuilder Query时,将Array作为参数值传递,显示为数组undefined。

    $list = array('13','197');

    $queryBuilder = function($repo) use ($user) {
    return $repo->createQueryBuilder('p')
        ->where('p.id IN (:stores)')
        ->setParameter('stores',$list);
        ->orderBy('p.name', 'ASC'); 
    }

1 个答案:

答案 0 :(得分:3)

您需要在lambda函数范围中包含$list变量。为此,您需要在use中提供此变量 - lambda函数定义的一部分:

$list = array('13','197');
$queryBuilder = function($repo) use ($user, $list) {
    return $repo->createQueryBuilder('p')
        ->where('p.id IN (:stores)')
        ->setParameter('stores',$list);
        ->orderBy('p.name', 'ASC'); 
}