2017-05-03 52 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 
    )); 
}