[英]Symfony 2.8 doctrine
我有一个简单的Abstract ApiController(从Controller扩展)类,在其中处理Auth。
protected function handleAuth(){
$login = $this->request->getUser();
$password = $this->request->getPassword();
$user = $this->get('doctrine.orm.entity_manager');
if (!$user)
{
return $this->sendResponse(array('msg'=>'User not found'),404);
}
$user = $user[0];
if(!password_verify($data['password'], $user->getUserPass())){
return $this->sendResponse(array('msg'=>'Invalid credentials'),401);
}
return true;
}
但是,在我的抽象控制器中获取教义会引发错误:
Error: Call to a member function get() on a non-object
in vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php at line 391
我如何在我的抽象课中获得学说?
为了使用$this->get(something.or.other)
,您的容器需要扩展ContainerAware
,如果您仅extends Controller
,它将自动执行。
作为2.8, ContainerAware
被弃用,取而代之的ContainerAwareTrait
,但如果你的抽象控制器仅仅简单地扩展控制器,那么你就不用担心自己这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.