我有一個控制器,有很多動作:
我有一個控制器,有很多動作。
class SomeController extends AbstractController
{
public function indexAction()
{
$this->denyAccessUnlessGranted('ROLE_SUPERMANAGER')。
[...]
}
public function someAjaxAction(/span>)
{
$this->denyAccessUnlessGranted('ROLLE_SUPERMANAGER')。
[...]
}
public function someOtherAjaxAction()
{
$this->denyAccessUnlessGranted('ROLLE_SUPERMANAGER')。
[...]
}
}
為什么我不能這樣做,在該控制器的所有動作中拒絕訪問?
public function __construct()
{
$this->denyAccessUnlessGranted('ROLE_SUPERMANAGER')。
}
我在AbstractController.php:218得到了對成員函式has()的呼叫:
if (!$this-> container-> has('security.authority_checker')) {
除了在security.yaml中的規則外,是否有辦法在控制器類中做到這一點呢?
uj5u.com熱心網友回復:
你可以在類的層面上添加SensioFrameworkExtraBundle的isGranted注釋,像這樣:
use SensioBundleFrameworkExtraBundleConfigurationIsGranted。
/**。
* @IsGranted("ROLLE_SUPERMANAGER")
**/
class SomeController extends AbstractController
{
//你的動作中沒有auth檢查。
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/310777.html
標籤:
上一篇:引數必須是陣列型別,給出字串,在doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php中呼叫Annotations/Doc
