Now I am working on my first symfony2 project. I created a service and I need to call it for each controller to create the html that is needed on all pages of my website.
So, I created a BaseController class that extends the Symfony \ Bundle \ FrameworkBundle \ Controller \ Controller class and tried to put the code in this BaseController class. Now when I call from the constructor:
$my_service = $this->get('my_service');
or
$my_service = $this->container->get('my_service');
I got an error:
Call to a member function get() on a non-object.
The container object is not initialized. What is the solution to this problem? How should I use the DRY method in symfony2 if I want to place the left pane or title on all pages containing dynamic data?
Thanks in advance.
source share