2013-12-09 4 views
15

Ich habe Code schreiben folgende für Daten aus der DatenbankFehler: Erwartete Lehre ORM query Lexer :: T_WITH erwartet, '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)); 
} } 

holen Aber es ist 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 » 

Need Ihre Hilfe Vielen Dank im Voraus

+0

sein entfernen '' AS' IGCNotificationBundle: Notifications n JOIN IGCNotificationBundle: Usernotifications U' – zzlalani

+0

Hallo Danke für die Antwort ich habe dies versucht, aber mit dem gleichen Fehler –

+0

Soweit ich es sehe, Sie versuchen, SQL auszuführen ... müssen Sie es in 'DQL' (Docrine Query Language) umschreiben. Bitte aktualisieren Sie Ihre Frage mit den Strukturen der Entitäten ... –

Antwort

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 » 

ich glaube, Sie Ihr Stichwort ‚ON‘ mit einem ‚mIT‘ ersetzen soll.

Extrakt aus 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

Ja, ich hatte das gleiche Problem mit Symfony 3 Doktrin, es funktioniert. Verwenden Sie 'WITH' anstelle von' ON' –

2

Bitte benutzen Sie den unten Code seine Arbeit für Sie

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