symfony - Global values: Define as service or define abstract Controller class? -


In my Symfony2 app, I want to get a value from my database on every template and do not want to call Each controller I know that I can define it as a service and inject it into my jogging templates (defining it as a twig global).

Is this a common and recommended way? Or should I make an abstract controller class where I get that value in my constructor and then get it from all my other controllers?

Note: This is not really a stable value, which is similar to all users, but this is a user-specific value that is different for each user.

If these variables were used to present the same place on your page If you go then you can present one. Like this:

  & lt; Div id = "sidebar" & gt; {{Render (Controller ('Your bundle: User: Statistics'))}}   

This will apply the entire output of your bundle / user controller / statistics to the #sidebardevice. Inside this action you can remove all the information you need.

If you need to use these variables in another way, then you should check it out.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -