doctrine 2 querybuilder with set parameters not working

前端 未结 2 1361
春和景丽
春和景丽 2021-01-23 09:19

this is my query:

public function getDetails($userid, $orderby, $sort){

$query = $this->_em->createQueryBuilder()
                ->select(\'u\'         


        
2条回答
  •  走了就别回头了
    2021-01-23 09:57

    You can't use placeholders for dinamical build of DQL query. You'll have to code it by your own:

    $sortBy = in_array($sortBy, array(...)) ? $sortBy : 'id';
    $sortDir = $sortDir == 'ASC' ? 'ASC' : 'DESC';
    
    $this->em->createQueryBuilder()
        ...
        ->orderBy('u.' . $sortBy, $sortDir)
    

提交回复
热议问题