我编写了以下代码来从数据库中获取数据:
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:错误:预期原则\ORM\查询\词法分析器::T_WITH,得到"ON" 500 内部服务器错误 - 查询异常 1 链接异常:查询异常 »
[Syntax Error] line 0, col 203: Error: Expected DoctrineORMQueryLexer::T_WITH, got 'ON' 500 Internal Server Error - QueryException 1 linked Exception: QueryException »
我认为您应该将关键字"ON"替换为"WITH"。
摘自文档:
现在可以在 DQL 中使用 语法
FROM Foo f JOIN Bar b WITH f.id = b.id
.
请使用下面的代码它为你工作
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 WITH 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));
}