mikrafizik
mikrafizik

Reputation: 349

Symfony 2.8 doctrine

I have an simple Abstract ApiController (extends from Controller) class, where i handle 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;
}

But it throws an erorr with getting doctrine in my Abstract Controller:

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

How can i get doctrine in my Abstract class?

Upvotes: 0

Views: 124

Answers (1)

Alec
Alec

Reputation: 2154

In order to use $this->get(something.or.other), your container needs to extend ContainerAware, which it will automatically do if you simply extends Controller.

As of 2.8, ContainerAware is deprecated in favor of ContainerAwareTrait, but if your abstract controller simply extends Controller, then you don't need to worry yourself with that.

Upvotes: 1

Related Questions