【发布时间】:2013-12-26 08:58:11
【问题描述】:
我编写了以下代码用于从数据库中获取数据:
function getnotificationAction()
{
$session = $this->getRequest()->getSession();
$userId = $session->get('userid');
$entitymanager = $this->getDoctrine()->getEntityManager();
$notification = $entitymanager->getRepository('IGCNotificationBundle:Notifications');
$userNotification = $entitymanager->getRepository('IGCNotificationBundle:Usernotifications');
$query = $entitymanager
->createQuery("SELECT n.notificationid, n.title,n.notificationmessage, u.creationdate, u.notificationid, u.messagestatus From IGCNotificationBundle:Notifications AS n JOIN IGCNotificationBundle:Usernotifications AS u ON u.notificationid = n.notificationid WHERE u.userId = :userId ORDER BY n.creationdate DESC")->setParameter('userId', userId);
$notifications = $query->getResult();
return $this->render('IGCNotificationBundle:Default:notification.html.twig', array('notifications' => $notifications));
} }
但它正在给予:
[语法错误] 第 0 行,第 203 列:错误:预期 Doctrine\ORM\Query\Lexer::T_WITH,得到 'ON' 500 内部服务器错误 - QueryException 1 链接异常:QueryException »
【问题讨论】:
-
可能会被删除
ASIGCNotificationBundle:Notifications n JOIN IGCNotificationBundle:Usernotifications u -
您好,感谢您的回复,我已经尝试过了,但遇到了同样的错误
-
据我所知,您正在尝试执行
SQL...您需要将其重写为DQL(Docrine Query Language)。请用实体的结构更新您的问题... -
嗨 @jperovic 我不知道如何在 DQL 中转换它
-
任何人都可以在dql查询中转换这个sql查询
标签: php symfony doctrine-orm