I often want to have my controllers be a service so you can inject some information. But at the same time i like to extend the base controller Symfony\Bundle\FrameworkBundle\Controller\Controller to have the convenience methods like $this->render. Now if you just create a service from your controller, you won't be able to use the methods anymore. You will get exceptions about calling get() on a non-object.
What you need to do is inject the service_container to your controller manually.
<service id="liip_vie.viecontroller" class="%liip_vie.viecontroller.class%" public="true">
<argument type="service" id="service_container"/>
...
</service>
services:
liip_vie.viecontroller:
class: %liip_vie.viecontroller.class%
arguments:
- "@service_container"
- ...
use Symfony\Component\DependencyInjection\ContainerInterface;
...
public function __construct(ContainerInterface $container, ...)
{
$this->setContainer($container);
...
}
Hope this helps. At least i always forget how to do it. Now i know where to look it up when i need it next time :-)