Symfony 2: global database query

How can I execute a database query on every page of a Symfony2 package?

I am trying to create online functionality, but this requires the request to be executed globally.

Thank!:)

+3
source share
3 answers

Interest Ask.

If you only need this inside a view (possibly a layout), I suggest creating a Twig Helper. You can access the Doctrine in a helper class. Check out this link:

http://www.kiwwito.com/article/extending-twig-in-symfony-2-add-custom-functions

+1
source

You can make a subpattern, for example (in my project) in my layout.html.twig I have this:

{% render "EUPaNdataBundle:Home:listAllInstitutes" %}

This will display a list of all institutes in the drop-down menu in the top navigation bar.

listAllInstitutes Home, listAllInstitutes.html.twig

+2

Create an event listener that listens for the event kernel.requestand updates the current user for the last time if he is logged in. See my other answer for an example listener and adapt it to your needs.

+2
source

All Articles