Laravel默认路由到404页面

编程入门 行业动态 更新时间:2024-10-28 12:28:50
本文介绍了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'); });

更多推荐

Laravel默认路由到404页面

本文发布于:2023-08-02 17:03:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1279563.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   页面   Laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!