Reputation: 47
How to check for author with Doctrine Query?
class UserController extends Controller
{ ...
/**
* @Route("/join/{id}", name="join_event")
*/
public function joinAct(Request $request, $id)
{
What Query for check? Condition: IF $id (field 'content_id') AND UserID (field 'user_id') exist in table, THEN message: 'You are an author!', ELSE do some code.
$authorcheck = $this->getDoctrine()
->getRepository('MyBundle:User')
->find($id AND $this->getUser()->getId());
End Query
if ($authorcheck) {
$message = ['text' => 'You are an author!', 'type' => 'success'];
}
else {
DoSomeCode...
}
}
}
Any ideas?
Upvotes: 0
Views: 127
Reputation: 29912
$authorcheck = $this
->getDoctrine()
->getRepository('MyBundle:User')
->findBy(array(
'id' => $id,
'user' => $this->getUser()
));
Should be fine for what you need.
As I don't know fields name and so on, you'll probably need to arrange this in order to work
Upvotes: 2