Reputation: 1972
What's the best and most efficient way to get some data from one entity and display it on every page? I'm using twig and doctrine.
I have an entity and database table which is only ever going to have one instance. It has things like company name etc. It's essentially configuration stuff so I know a config file is more efficient but I want it to be editable by an admin user.
I guess I'm asking two questions. Where do I put the code to retrieve the entity on every request and how do I get the data into my top level twig template?
Thanks
Upvotes: 2
Views: 622
Reputation: 2191
It is not the answer to your actual question, but I think it solves the same problem. I am using SonataBlockBundle to render one specific editable Block in my Footer. I don't think you need a real single Entity which has fields for Adress, company name etc. It could be enought to have a content Block and put the HTML in it, so you are more flexible to add some content, like copyrights or something similar.
This approach might also be to much effort, because implementing the BlockBundle is a little bit more challenging than rendering an controller, but it might be worth looking into, because you can use it also for many other things.
Upvotes: 1
Reputation: 14598
You need to embed a controller.
At some point, you will also want to do some caching for something like this.
Upvotes: 3