2014-11-25 129 views
0

我尝试实现我的网站的404页面的代码。即时通讯使用此代码在我的filters.php,但我也试图在global.phpLaravel误差404页

App::missing(function($exception) 
{ 
return View::make('404'); 
} 

使用结果即时得到这个错误:

Symfony \ Component \ Debug \ Exception \ FatalErrorException 
Call to a member function getAction() on a non-object 
+0

可能重复的[Laravel 4 - 自定义404错误处理仅fo ④短缺页] [1] [1]:http://stackoverflow.com/questions/24185735/laravel-4-custom-404-error-handling-only-for-missing-pages – 2014-11-25 09:31:24

回答

1

我做的aother方式。 这是怎么回事时,404上升通常是在应用程序中声明发生/开始/ global.php

它应该看起来像这样:

App::error(function($exception, $code) 
{ 
    switch ($code) 
    { 
     case 403: 
      return Response::view('errors.403', array(), 403); 
     case 404: 
      return Response::view('errors.404', array(), 404); 
    } 
} 

这只是所谓的应用程序/视图/错误/ 404。 blade.php随时laravel提出了404或如果你决定手动调用App :: abort(404);

希望它有帮助。

0

我GOOGLE了更多关于这一点,我如何理解它的问题来自nginx的。可能?顺便说一句,它没有刀片模板工作,但我需要它。所以需要找出如何解决它

0

,看起来像在布局或你的404页面的观点或作曲家。你有这样的:

Route::getCurrentRoute()->getAction() 

Route::current()->getAction() 

或者据我记得路线:: getCurrentRoute时,404会是零,然后它说明你的错误...

我使用检查当前路由是否为路由的实例:

$currentRoute = \Route::getCurrentRoute(); 
if ($currentRoute instanceof Route) { 
    // Do What you want here 
    $currentRoute->getAction()//... 
} 
+0

中当然一条路线是一条路线,为什么你要检查那个heck – 2015-01-02 13:32:11

+0

你是对的我不知道为什么我虽然我得到了这个问题... – Clempat 2015-01-06 18:31:13