为什么在控制器内部调用控制器时会出现以下错误?
致命错误:在第 149 行的 /home/web/project/ symfony2 /vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php中的非对象上调用成员函数 get()
在控制器中,我调用了一个扩展类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
在控制器中调用服务、原则或其他类似的东西时,发生了错误。否则,它会起作用。
例如,我如何在此类中使用教义?