我想使用以下查询来订购商店下订单的日期。我想按升序执行它们,但是当我尝试测试运行时出现以下错误:
[Syntax Error] line 0, col 7: Error: Expected IdentificationVariable | ScalarExpression | AggregateExpression | FunctionDeclaration | PartialObjectExpression | "(" Subselect ")" | CaseExpression, got 'order'
$orderSales = $this->getDoctrine()->getRepository("AppBundle:Order")->createQueryBuilder('order');
$orderSales->orderBy('order.date', 'asc');
$orderSales = $orderSales->getQuery();
$orderResult = $orderSales->getResult();
我在 .twig 模板中渲染 orderResult
return $this->render('admin/store/sales/adminsales.html.twig', array(
'orderResult' =>$orderResult
));
最佳答案
您应该在您的存储库中声明您的 QueryBuilder,例如 (createQueryBuilder 接受参数):
public function findOrdersByDate()
{
$qb = $this->createQueryBuilder('o')
->orderBy('o.date', 'asc');
return $qb
->getQuery()
->getResult();
}
在你的 Controller 中:
$orderResult = $this->getDoctrine()->getRepository("AppBundle:Order")->findOrdersByDate();
编辑:正如 Imanali Mamadiev 所指出的:将“order”替换为“o”以避免 SQL 关键字冲突
关于php - 订单日期查询,语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36398915/