Laravel默认路由到404页面
问题描述:
我正在使用Laravel 4框架,并且定义了很多路由,现在我想知道所有未定义的url,如何将它们路由到404页面?
I'm using Laravel 4 framework and I've defined a whole bunch of routes, now I wonder for all the undefined urls, how to route them to 404 page?
答
未定义的路由会触发 Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
异常,您可以在app/start/global中对其进行处理.使用App :: error()方法的php如下:
Undefined routes fires the Symfony\Component\HttpKernel\Exception\NotFoundHttpException
exception which you can handle in the app/start/global.php using the App::error() method like this:
/**
* 404 Errors
*/
App::error(function(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $exception, $code)
{
// handle the exception and show view or redirect to a diff route
return View::make('errors.404');
});