我编写了以下代码来从数据库中获取数据
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)); } }
但它是givin
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)); } }
需要你的帮助提前致谢