简体   繁体   English

Laravel 404页面错误

[英]Laravel error with 404 page

im trying to implement code of 404 page in my website. 我试图在我的网站上实现404页面的代码。 Im using this code in my filters.php but i also tried to use in global.php 我在我的filters.php中使用此代码,但我也尝试在global.php中使用

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

as a result im getting this error: 结果即时通讯收到此错误:

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

i do it an aother way. 我是另一种方式。 What is going to happen when 404 is raised is normally declared in app/start/global.php 通常在app / start / global.php中声明提高404时会发生什么

It should looks like that : 它看起来应该像这样:

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);
    }
}

This just called the app/views/errors/404.blade.php anytime laravel raised a 404 or if you decide to manually call App::abort(404); 当laravel提出404或您决定手动调用App :: abort(404)时,这仅称为app / views / errors / 404.blade.php。

Hope it helps. 希望能帮助到你。

I googled more about this and how i understand it problem comes from nginx. 我在Google上搜索了更多有关它以及我如何理解它的问题,这些问题来自nginx。 could be? 可能? btw it is working without blade templating but i need it. 顺便说一句,它没有刀片模板工作,但我需要它。 so need to find out how to fix it 所以需要找出解决方法

That look like in the views or composer of the layout or your 404 page. 在布局或404页面的视图或编写器中看起来像。 you have something like: 你有类似的东西:

Route::getCurrentRoute()->getAction()

or 要么

Route::current()->getAction()

Or as far I remember Route::getCurrentRoute when 404 would be null and then it explains your error... 或到目前为止,我记得Route :: getCurrentRoute,当404为null时,它将说明您的错误...

I use to check if the current Route is instance of Route by: 我用来检查当前Route是否是Route by的实例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM