this is my 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' is not defined.
how do i get the orderby from the properties in that function to the query?
You can't use placeholders for dinamical build of DQL query. You'll have to code it by your own:
You cant bind parameters to QueryBuilder, only to Query, so just swap lines, first get query out of builder, then fill it with parameters and get result.
In doctrine 2.4 its fixed, and you can bind parameters to QueryBuilder.
Update: i've missed moment with placeholder in field name, SQL do not support such constructions.