I'm converting an application over from a legacy framework to Symfony2. One of the things the app has is a tiny little message in the bottom corner of the rendered page that says
served by appserver3 in 200ms
or similar. It changes depending on the appserver you're on and the amount of time it took to serve the request. The value for the appserver is set in a config file (but that's largely irrelevant here).
Should I create a BaseController
type class that extends Controller
and then have all my controllers extend that? If so, how would I go about making sure that the BaseController
always adds the responseTime
and appServerName
to the list of variables that will be passed to my twig template without having to add it manually in every controller like this:
// e.g. src/MyNamespace/MyBundle/Controller/AboutUsController.php
return $this->render('MyNamespaceMyBundle:Default:index.html.twig', array('var1' => $var1, 'appServerName' => $this->getAppServerName(), 'responseTime' => $this->getResponseTime()));
(Obviously this would assume that I created the getAppServerName
and getResponseTime
methods in my BaseController
.)
This seems like a lot of copypasta and my whole reason for moving to Symfony2 is to avoid that :\