A
A
Alexey Krichko2014-01-21 18:00:39
symfony
Alexey Krichko, 2014-01-21 18:00:39

What's the best way to display certain entities on all pages, Symfony 2.3?

For example, on all pages I need the latest three news. An easy way is to subrequest from a template (like twig's render). But this is a waste of resources. Another way is to pass them as parameters from each action, but this smacks of pointless code duplication, and I don't like it either. I started by using KnpMenuBundle, which extends twig to allow access to the menu builder. When the entities became more complex, I began to redefine the appearance of the menu in twig templates and pass additional properties as attributes of the menu element. But looking back at what I've done, I can only shake my head sadly. I think the answer lies somewhere in the area of ​​services.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2014-01-21
@sand_alkr

you can request a specific controller action in the template. As a result, a new request will be generated in the appkernel with a note that this is not a master request, and the response of this action will be displayed in the right place in the template.
symfony.com/doc/2.3/book/templating.html#embedding...

R
Ruslan Kasymov, 2014-01-21
@HDAPache

I'm not familiar with Symfony, but in YII I write a widget in such a situation. And in order not to pull the database every time I use a tagged cache.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question