Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2: Global Database Query

Tags:

php

symfony

How would I go about executing a database query on every page within a Symfony2 bundle?

I'm attempting to create a who's online functionality but this requires a query to be executed globally.

Thanks! :)

like image 813
David T Avatar asked Sep 28 '26 09:09

David T


1 Answers

You can render a sub-template, for example (in a project of mine) in my layout.html.twig I have this:

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

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

listAllInstitutes is an action in the Home controller which gets a list of institutes from the DB and then returns the listAllInstitutes.html.twig template

like image 179
Flukey Avatar answered Sep 29 '26 23:09

Flukey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!