尝试在Silex上拥有自己的404错误树枝页面,我在渲染模板时遇到了问题。我想应该是一个身份验证问题,但无法找到位置和内容:/
这是我的app.php:
use \Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
// 404 - Page not found
$app->error(function (\Exception $e) use ($app) {
if ($e instanceof NotFoundHttpException) {
return $app['twig']->render('error.html.twig', array(
'code' => '404',
));
}
$code = ($e instanceof HttpException) ? $e->getStatusCode() : 500;
return $app['twig']->render('error.html.twig', array(
'code' => $code,
));
});
但是我得到了同样的错误:
mod_fcgid:stderr:PHP致命错误:未捕获异常' Symfony \ Component \ Security \ Core \ Exception \ AuthenticationCredentialsNotFoundException'带消息'令牌存储不包含身份验证令牌。一个可能的原因可能是没有为此URL配置防火墙。'在/var/www/vhosts/dogsupdate.com/backend.dogsupdate.com/vendor/symfony/security/Core/Authorization/AuthorizationChecker.php:57
关键是,如果我返回一个json错误,它可以工作:
// 404 - Page not found
$app->error(function (\Exception $e) use ($app) {
if ($e instanceof NotFoundHttpException) {
return $app->json(array('error' => 'Page Not Found'), 404);
}
$code = ($e instanceof HttpException) ? $e->getStatusCode() : 500;
return $app->json(array('error' => $e->getMessage()), $code);
});