3 回答

TA貢獻2021條經(jīng)驗 獲得超8個贊
bin/console debug:event-dispatcher kernel.request
幫助解決了這個問題。我正在使用
tags:
- { name: kernel.event_listener, event: kernel.response, method: onKernelResponse, priority: 10 }
在 Services.yml 中,它與
getSubscribedEvents()
因此我刪除了標簽,只保留了
public static function getSubscribedEvents()
{
return array(
KernelEvents::REQUEST => array('onKernelRequest', 10),
);
}
然后我通過給予其他兩個監(jiān)聽器高優(yōu)先級來將身份驗證監(jiān)聽器移到下方,就像在 symfony 2.8 中一樣

TA貢獻1818條經(jīng)驗 獲得超11個贊
將AuthorizationChecker注入您的班級
protected $authChecker;
public function __construct(AuthorizationChecker $authChecker)
{
$this->authChecker = $authChecker;
}
通過將其注入您的service.yml
XXXXXXXXX:
class: App\XXX\XXXX\XXXXX
arguments: [ "@security.authorization_checker" ]
然后使用它使用isGranted檢查角色
if ($this->authChecker->isGranted('IS_AUTHENTICATED_ANONYMOUSLY')) {
}
- 3 回答
- 0 關注
- 204 瀏覽
添加回答
舉報