在我的Symfony2應用程序中,當頁面未找到(404)時出現錯誤,並且我嘗試在我的onKernelRequest事件類中使用isGranted方法。Overriden onKernelRequest事件
所以問題是:如何檢查頁面是否在事件類中找到?
//編輯
一些代碼:
public function onKernelRequest(GetResponseEvent $event) {
$session = $event->getRequest()->getSession();
$securityContext = $this->serviceContainer->get('security.context');
/* The line below makes the script throw the following error:
Fatal error: Uncaught exception 'Symfony\Component\Routing\Exception\ResourceNotFoundException' in C:\xampp................ in C:\xampp\....\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\EventListener\RouterListener.php on line 144
*/
if ($securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
// ...
} else {
// ...
}
}
你是怎麼定製錯誤的水電站? – Darmen
通過將error.html.twig和error404.html.twig文件放在app/Resources/TwigBundle/views/Exception –
我已經更新了這個問題。請重新閱讀 –