2017-05-03 50 views
0

我在我的控制器的以下功能:如何拒绝Symfony中的其他用户访问?

/** 
    * @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 
     )); 
    } 
} 

据工作完美,但我要为其他用户我不承认存取权限。 e只有当前登录的用户可以访问他的收入清单。现在,当我更改网址中的ID时,它会打开其他用户的收入。

回答

2

你试过这样吗?

/** 
* @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 
    )); 
}