【发布时间】:2012-05-23 08:05:07
【问题描述】:
为什么在控制器内部调用控制器会报如下错误?
致命错误:在非对象上调用成员函数 get() /home/web/project/symfony2/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php 在第 149 行
在控制器中,我调用了一个扩展 Controller 的类:
class DemoController extends Controller
{
public function indexAction()
{
$object = new \Acme\DemoBundle\Service\Object();
$object->method();
}
// ...
}
类是这样的:
# Acme/DemoBundle/Service/Object.php
class Object extends Controller
{
public function method()
{
$em = $this->getDoctrine()->getEntityManager(); // the problem
// ...
}
}
当我在控制器中使用$this 调用服务、原则或其他类似内容时,发生了错误。否则,它可以工作。
例如,我如何在此类中使用教义?
【问题讨论】:
标签: symfony