Notification controller
<?php
namespace Main\AdminBundle\Controller;
/* included related namespace */
use Symfony\Component\PropertyAccess\PropertyAccess;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Query;
use Main\AdminBundle\Entity\Notificationmaster;
class NotificationController extends BaseController
{
protected $session;
protected $em;
public function __construct(EntityManager $em)
{
$this->em = $em;
}
/**
* @Route("/Notification1/{salon_id}",defaults={"salon_id":""})
* @Template()
*/
public function indexAction($salon_id)
{
return array("j"=>"jj");
}
/**
* @Route("/Notification/create/{notification_type}/{notification_title}",defaults={"notification_type":"","notification_title":""})
*/
public function notificationcreateAction($notification_type,$notification_title)
{
//$this->em = $em;
$notificationmaster = new Notificationmaster();
$notificationmaster->setNotification_type($notification_type);
$notificationmaster->setNotification_title($notification_title);
$em = $this->getDoctrine()->getManager();
$em->persist($notificationmaster);
$em->flush();
return $notificationmaster->getNotification_master_id();
}
/**
* @Route("/Notification/List/{notification_for}/{notification_to}/{lang_id}",defaults={"notification_for":"","notification_to":"","lang_id":""})
*/
public function notificationlistAction($notification_for,$notification_to,$lang_id)
{
//$em = $this->getDoctrine()->getManager();
return new Response(json_encode("hi"));
}
}
in twig file
{% set notification_html = render(controller('MainAdminBundle:Notification:notificationlist',{"notification_for":"organization","notification_to":"1","lang_id":"1"})) %}
Base Controller
class BaseController extends Controller{
public function __construct()
{
date_default_timezone_set("Asia/Calcutta");
}
}
i got this error while i m calling notification list action using Twig file( as above )
Catchable Fatal Error: Argument 1 passed to Controller::__construct() must be an instance of Doctrine\ORM\EntityManager, none given, called
if i remove entity manager , then i got an error in create action Like
Error: Call to a member function has() on a non-object
because i call this create action using this
$notification = new NotificationController($em);
$notification_id = $notification->notificationcreateAction('appointment_book','New Appointment');
so i have to add entity manager .
BaseController
look like? – Jason Roman