我想将排序类型作为参数。所以我写了函数
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();
}
但它不适用于致命错误 Uncaught exception 'Doctrine\ORM\Query\QueryException' with message '[Syntax Error] line 0, col 77: Error: Expected end of string, got '?'' in C:\Users \user\Desktop\projects\interview\application\libraries\Doctrine\ORM\Query\QueryException.php:42 堆栈跟踪:#0 C:\Users\user\Desktop\projects\interview\application\libraries\Doctrine\ORM\ Query\Parser.php(380): Doctrine\ORM\Query\QueryException::syntaxError('line 0, col 77:...') #1 C:\Users\user\Desktop\projects\interview\application\libraries \Doctrine\ORM\Query\Parser.php(745): Doctrine\ORM\Query\Parser->syntaxError('end of string') #2 C:\Users\user\Desktop\projects\interview\application\libraries\ Doctrine\ORM\Query\Parser.php(213): Doctrine\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 在第 42 行
还有其他方法如何按参数设置排序类型吗?