2013-12-09 1 views
15

devo scrivere seguente codice per il recupero dei dati dal databaseErrore: Previsto Doctrine ORM Query Lexer :: T_WITH, ha 'ON'

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

ma è GIVIN

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

Bisogno il vostro aiuto Grazie in anticipo

+0

può essere rimuovere '' AS' IGCNotificationBundle: Notifiche n ENTRA IGCNotificationBundle: Usernotifications u' – zzlalani

+0

Ciao grazie per la risposta ho provato questo, ma di fronte lo stesso errore –

+0

Per quanto vedo che stai cercando di eseguire 'SQL' ... è necessario riscriverlo a' DQL' (Docrine Query Language). Per favore aggiorna la tua domanda con la struttura delle entità ... –

risposta

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

penso che si dovrebbe sostituire la parola chiave 'ON' con un 'cON'.

estratto 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 .

+0

Sì, ho avuto lo stesso problema con la dottrina di Symfony 3, funziona. Devo usare 'WITH' invece di' ON' –

2

Utilizza il codice qui sotto il suo lavoro per voi

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