php 错误:预期的 Doctrine\ORM\Query\Lexer::T_WITH,“ON”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20467428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: Expected Doctrine\ORM\Query\Lexer::T_WITH, got 'ON'
提问by Vishal Mokal
I have written the following code for fetching data from database:
我编写了以下代码来从数据库中获取数据:
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));
} }
But it is giving:
但它给出了:
[Syntax Error] line 0, col 203: Error: Expected Doctrine\ORM\Query\Lexer::T_WITH, got 'ON' 500 Internal Server Error - QueryException 1 linked Exception: QueryException ?
[语法错误] 第 0 行,第 203 行:错误:预期的 Doctrine\ORM\Query\Lexer::T_WITH,出现“ON”500 内部服务器错误 - QueryException 1 链接异常:QueryException?
回答by BENARD Patrick
[Syntax Error] line 0, col 203: Error: Expected Doctrine\ORM\Query\Lexer::T_WITH, got 'ON' 500 Internal Server Error - QueryException 1 linked Exception: QueryException ?
I think you should replace your keyword 'ON' with a 'WITH' .
我认为您应该将关键字 'ON' 替换为 'WITH' 。
extract from doc :
从文档中提取:
Joins between arbitrary entities are now possible in DQL by using the syntax
FROM Foo f JOIN Bar b WITH f.id = b.id.
现在可以使用语法在 DQL 中连接任意实体
FROM Foo f JOIN Bar b WITH f.id = b.id。
回答by Mitul
Please use the bellow code its work for you
请使用以下代码为您工作
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));
}

