0

Someone told me to use flag, but I'm using in base template(where I have menus) to display the message notification which was unable to do.

class countMail extends Controller{

    public function indexAction(){
        $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 $this->render('admin/countMail.html.twig', [
                    'count' => $count
        ]);
    }

}

In twig

{% extends "base.html.twig" %}
{% block count %}

    {{ count }}

{% endblock %}
Imanali Mamadiev
  • 2,604
  • 2
  • 15
  • 23
Pranan Subba
  • 186
  • 3
  • 10
  • Why should we lose time trying to understand your code if you don't take time to format .. – Mcsky Nov 24 '17 at 16:52
  • You should have a look at flash messages: https://symfony.com/blog/new-in-symfony-3-3-improved-flash-messages – Tokeeen.com Nov 24 '17 at 17:13

1 Answers1

0

Your question is confusing. But I think the following steps will help you.

  1. You need to write a service that will output the number of emails. Refer https://symfony.com/doc/3.0/service_container.html or https://symfony.com/doc/current/controller/service.html for write a service.
  2. Then you need to call this service from the twig, and you will get what you need. Check symfony2: how to access service from template for it.
Nightfox
  • 488
  • 3
  • 11