doctrine2 - doctrine 2 querybuilder with set parameters not working -
this query:
public function getdetails($userid, $orderby, $sort){
$query = $this->_em->createquerybuilder() ->select('u') ->from('\entities\users', 'u') ->where('u.userid= ?1') ->orderby('u.?3', '?3') ->setparameter(1, $userid) ->setparameter(2, $orderby) ->setparameter(3, $sort) ->getquery() ->getresult(); }
it keeps erroring: message: [semantical error] line 0, col 83 near '?3 desc': error: '?3' not defined.
how orderby properties in function query?
you can't use placeholders dinamical build of dql query. you'll have code own:
$sortby = in_array($sortby, array(...)) ? $sortby : 'id'; $sortdir = $sortdir == 'asc' ? 'asc' : 'desc'; $this->em->createquerybuilder() ... ->orderby('u.' . $sortby, $sortdir)
Comments
Post a Comment