错误:预期的Doctrine \ ORM \ Query \ Lexer :: T_WITH,“开启”

时间:2013-12-09 09:38:25

标签: php symfony doctrine-orm

我编写了以下用于从数据库中获取数据的代码:

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»

2 个答案:

答案 0 :(得分:42)

[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 »

我认为您应该使用'WITH'替换关键字'ON'。

摘自doc:

  

现在可以使用DQL在DQL中连接任意实体   语法FROM Foo f JOIN Bar b WITH f.id = b.id

答案 1 :(得分:1)

请使用它为您工作的波纹管代码

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));
}