2014-03-19 104 views
0

如何在操作中调用App :: abort(404),该操作不存在?Laravel 4 rest controller 404 error

当我去url/logindfghdfghdfghhdfgh(一些非真实的url)时,我想显示404页面,但它显示我在控制器中的第一个动作。

请帮帮

Route::get('/login', '[email protected]'); 
Route::post('/login', '[email protected]'); 

Route::group(array('before' => 'auth'), function(){ 
    Route::controller('/codes', 'CodeController'); 
}); 

Route::controller('/users', 'UserController'); 

Route::controller('/', 'PromoController'); 
+0

请向我们展示您的路线。 –

+0

已更新问题 – KoIIIeY

+0

您是否添加了像http://laravel.com/docs/errors#handling-404-errors – JackPoint

回答

0

由于JackPoint在评论中提到,如果添加了将要被拉到在启动时,如

App::missing(function($exception) 
{ 
    return Response::view('errors.missing', array(), 404); 
}); 

地方。在app/start/global.php中可以工作,那么它应该在404上显示一个自定义错误页面 - 在上面的例子中,你需要在你的views文件夹下有一个错误文件夹,并在那里有一个missing.blade.php视图文件如果您使用的是刀片视图)。

+0

这不工作,可能有更多的选择? – KoIIIeY

0
if(!Request::is('/')){ 
     App::abort(404); 
    } 

我在我的get()方法中添加了这个,它与App :: missing()一起使用。