我想將排序類型作爲參數。所以我寫了功能Doctrine2:帶參數的DQL
public function findInterval($pageNumber, $limit, $sortType) {
$query = $this->_em->createQuery('Select c from Entities\Comment c where c.isremoved=0 ORDER BY c.creationdate ?1');
$query->setParameter(1, $sortType); //sortType is either ASC or DESC
return $users = $query->getResult();
}
不過,這並不致命錯誤 未捕獲的異常「學說\ ORM \查詢\ QueryException」有消息「[語法錯誤] 0行,列77工作:錯誤:預期年底字符串,在C:\ Users \ user \ Desktop \ projects \ interview \ application \ libraries \ Doctrine \ ORM \ Query \ QueryException.php:42堆棧跟蹤:#0 C:\ Users \ user \ Desktop \ (380):Doctrine \ ORM \ Query \ QueryException :: syntaxError('line 0,col 77:...')#1 C:\ Users (745):Doctrine \ ORM \ Query \ Parser-> syntaxError('end of string')#2 C:\ Users \ Desktop \ Projects \ interview \ application \ libraries \ user \ Desktop \ projects \ interview \ application \ libraries \ Doctrine \ ORM \ Query \ Parser.php(213):Doctrin e \ ORM \ Query \ Parser-> QueryLanguage()#3 C:\ Users \ user \ Desktop \ projects \ interview \ application \ libraries \ Doctrine \ ORM \ Query \ Parser.php(288):Doctrine \ ORM \ Query \ Parser-> getAST()#4 C:\ Users \ user \ Desktop \ projects \ interview \ application \ libraries \ Doctrine \ ORM \ Query.php(230):Doctrine \ ORM \ Query \ Parser-> parse()#5 C:\ Users \ user \ Deskt C:\ Users \ user \ Desktop \ projects \ interview \ application \ libraries \ Doctrine \ ORM \ Query \ QueryException.php on line 42
有沒有其他方法如何設置按參數排序類型?