下午好,我已经在Silex Skeleton的几个项目中使用了并没有意识到他们所有的异常代码都没有正确返回,请使用以下代码
$app->error(function (\Exception $e, $code) use ($app) {
if ($app['debug']) {
return;
}
// 404.html, or 40x.html, or 4xx.html, or error.html
$templates = array(
'errors/'.$code.'.html',
'errors/'.substr($code, 0, 2).'x.html',
'errors/'.substr($code, 0, 1).'xx.html',
'errors/default.html',
);
return new Response($app['twig']->resolveTemplate($templates)->render(array('code' => $code)), $code);
});
当打印变量$ code时,我给出了以下内容:
GET /demos/ HTTP/1.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Accept-Encoding: gzip, deflate, sdch Accept-Language: es,en;q=0.8 Cache-Control: max-age=0 Connection: keep-alive Cookie: _ga=GA1.2.33103823.1399416189; _CRM=0nonn2h02c4mbhgbdvjhs8d852 Host: crmtyc.domainame.com User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36
在本地和生产服务器上。
感谢您的任何意见或建议。