Laravel 路由和 404 错误 [英] laravel routing and 404 error
本文介绍了Laravel 路由和 404 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想指定,如果在 url 地址中输入了除现有路由之外的任何内容(在 routes.php 中,则显示 404 页面.
I want to specify that if anything entered in the url address other than existing routes (in routes.php, then show 404 page.
我知道:
App::abort(404);
但是如何指定除定义的路由之外的所有其他内容的部分?
but how can I specify the part where everything else except the routes defined?
推荐答案
您可以将此添加到您的 filters.php 文件中:
You can add this to your filters.php file:
App::missing(function($exception)
{
return Response::view('errors.missing', array(), 404);
});
并创建 errors.missing
视图文件以向他们显示错误.
And create the errors.missing
view file to show them the error.
另请查看错误和记录文档
编辑
如果你需要向那个视图传递数据,第二个参数是一个你可以使用的数组:
If you need to pass data to that view, the second parameter is an array you can use:
App::missing(function($exception)
{
return Response::view('errors.missing', array('url' => Request::url()), 404);
});
这篇关于Laravel 路由和 404 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文