【发布时间】:2014-01-08 09:27:45
【问题描述】:
我有一个扩展 controller (Symfony\Bundle\FrameworkBundle\Controller\Controller) 的自定义控制器,它又扩展了 ContainerAware (Symfony\Component\DependencyInjection\ContainerAware)。
在我使用的所有功能中;
$foo = $this->get('foo');
所以我希望能够像这样构建我的班级;
<?php
class FooController extends Controller
{
private $fooManager;
function indexAction()
{
// ...
$this->fooManager->getAllFoo($scope);
// ...
}
}
在我的自定义类中添加构造函数将不起作用,因为 ContainerAware 将容器设置为 setContainer(ContainerInterface $container = null) 函数。
我已经尝试在我的控制器中覆盖这个函数,但还是不行。
我该如何实现?
【问题讨论】: