Controller
$count_em = $this->getDoctrine()->getRepository('AppBundle:St_Jude_Email');
$count_dql = $count_em->createQueryBuilder('c')
->select('count(c.flag)')
->where('c.flag = 0');
$flag_count = $count_dql->getQuery();
$count = $flag_count->getSingleScalarResult();
return $count;
Config.yml
Twig:
globals:
count: '@AppBundle\Controller\countMail'
How to display count which is global in twig?? I'm sorry, I'm new to the symfony and have no idea how to display 'count' in twig. I tried doing {{ count }} , but got error 'An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Object of class AppBundle\Controller\countMail could not be converted to string").'
You should create a service e.g.
MailService
, which holds e.g. acountAllMail()
method. In this method you can do your DB stuff. After that you can do the following:config.yml
And in your twig template you can use your service like this