如何解决Laravel 5.1中的“NotFoundHttpException”错误

时间:2015-10-29 05:35:00

标签: php oop laravel frameworks

我在尝试访问我在路线中添加的页面时遇到此错误。 恩。 laravel.com/about-us

这是我的路线代码示例。 我被要求在config.php中进行路由

'about-us' => [
            'controller' => 'page',
            'method' => 'about',
            'enable' => true
        ],

和这样的方法。

public function about() {
        return view($this->getViewPrefix() . '::page.about');
    }

完全错误:

NotFoundHttpException in Application.php line 879:
in Application.php line 879
at Application->abort('404', '', array()) in helpers.php line 21
at abort('404') in helpers.php line 45
at cd_abort('404') in routes.php line 93
at ServiceProvider->{closure}('about-us')
at call_user_func_array(object(Closure), array('param1' => 'about-us')) in Route.php line 155
at Route->runCallable(object(Request)) in Route.php line 130
at Route->run(object(Request)) in Router.php line 704
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 706
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 671
at Router->dispatchToRoute(object(Request)) in Router.php line 631
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54

我个人认为这不是我做这些事情的方式,因为我的一位同事有两个这样的页面工作,(他们只有两个)... 这与我的安装,或者我的操作系统有什么关系吗?

2 个答案:

答案 0 :(得分:1)

我认为你不能在配置文件中写路由。您必须在此文件中编写路线Route::get('about-us', [ 'as' => 'aboutUs', 'uses' => 'PagesController@about' ]); 写下这些行

app/Http/Controllers

编写控制器的名称而不是PagesController。您必须将控制器放在此文件夹{{1}}

答案 1 :(得分:0)

Laravel有routes.php文件来包含所有与应用程序相关的路由。应用程序运行时,该文件将自动加载。

因此,请在此文件中包含您的路由以获得最佳效果。

A" get"路由将像:

Route::get('/about-us', [ 'as' => 'about', 'uses' => 'PagesController@about']);

同样的'帖子'路由:

Route::post('/about-us', [ 'as' => 'about', 'uses' => 'PagesController@about']);

请记住将控制器文件命名为" PagesController"。它是正确的命名约定。

" @约"是PagesController中处理逻辑的方法。

为了更好地理解:Laravel Routing

希望这有用。