I would venture to suggest, based on a quick look at the source code for Symfony: you still need to declare that you adhere to the ContainerAwareInterface interface.
Here's what the code looks like when Symfony installs the container on the controller.
if ($controller instanceof ContainerAwareInterface) { $controller->setContainer($this->container); }
So, I suppose you need to do something like this:
use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerAwareTrait; // ... class MainController implements ContainerAwareInterface { use ContainerAwareTrait; /** * @Route("/", name="_index") * @Template() */ public function indexAction() { var_dump($this->container); return array(); }
}
As an aside, this is probably a pretty good example for Duck Typing , especially if they called the method something more specific or if it was cheaper to check the parameter types for methods at runtime
Chris trahey
source share