Reputation: 498
I have the following function in my Controller:
/**
* @Route("/incomes/show/{id}", name="incomes_show")
*/
public function listIncomesAction($id)
{
$user = $this->getDoctrine()->getRepository('AppBundle:User')->find($id);
$userIncomes = $user->getIncomes();
return $this->render('incomes/show.user.incomes.html.twig', array(
'incomes' => $userIncomes
));
}
}
It is working perfectly, but i want to denied acces for other users i. e only the current logged in user have access to his list of incomes. Now when i change the id in the URL, it opens the other users incomes.
Upvotes: 0
Views: 44
Reputation: 3135
Did you try like this ?
/**
* @Route("/incomes/show", name="incomes_show")
*/
public function listIncomesAction()
{
$user = $this->getUser();
$userIncomes = $user->getIncomes();
return $this->render('incomes/show.user.incomes.html.twig', array(
'incomes' => $userIncomes
));
}
Upvotes: 2