dsdapobp26141 2015-05-14 16:08
浏览 36
已采纳

路由在Laravel 5.0上无法正常工作(404错误)

I switched to Laravel 5.0 and try to introduce myself.

I have a small problem which confuses me:

I use two Controller classes. The first works fine but the second one gets ignored. Could somebody tell me why?

routes.php

<?php
Route::controller('/', 'IndexController');
Route::controller('/rezeptliste', 'RecipelistController');

IndexController.php

<?php namespace App\Http\Controllers;

class IndexController extends Controller {
    public function getIndex() {
        return view('index');
    }
}

RecipelistController

<?php namespace App\Http\Controllers;

class RecipelistController extends Controller {
    public function getIndex() {
        return view('recipelist');
    }
}

When I access / it works perfectly. When I try to access /rezeptliste I get the following error:

NotFoundHttpException in Controller.php line 259:
Controller method not found.
in Controller.php line 259
at Controller->missingMethod('rezeptliste')
at call_user_func_array(array(object(IndexController), 'missingMethod'), array('_missing' => 'rezeptliste')) in Controller.php line 246
at Controller->callAction('missingMethod', array('_missing' => 'rezeptliste')) in ControllerDispatcher.php line 162
at ControllerDispatcher->call(object(IndexController), object(Route), 'missingMethod') in ControllerDispatcher.php line 107
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 108
at ControllerDispatcher->callWithinStack(object(IndexController), object(Route), object(Request), 'missingMethod') in ControllerDispatcher.php line 67
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\IndexController', 'missingMethod') in Route.php line 204
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 701
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Router.php line 703
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 670
at Router->dispatchToRoute(object(Request)) in Router.php line 628
at Router->dispatch(object(Request)) in Kernel.php line 214
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 43
at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 17
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Kernel.php line 115
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
at Kernel->handle(object(Request)) in index.php line 53
  • 写回答

3条回答 默认 最新

  • douyou3619 2015-05-14 16:20
    关注

    The problem here is that in Laravel routes are evaluated in the order listed.

    This means that since your very first route '/' matches the route /rezeptliste too, laravel will instead go to the IndexController and look for a method called "rezeptliste".

    Instead your routes should be ordered like this:

    <?php
    Route::controller('/rezeptliste', 'RecipelistController');
    Route::controller('/', 'IndexController');
    

    That way your specialized url of /rezeptliste will be "caught" first and sent to the RecipelistController, rather then being caught by the IndexController route.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 在误装Windows server2019 后如何利用Windows.old恢复?
  • ¥20 代码实现状态连接包过滤防火墙的设计与实现
  • ¥15 vscode的红色箭头爆红和has no default export报错
  • ¥15 关于#sql#的问题:#情况描述 在用vs对项目进行调试时,出现找不到网络路径,然后查看SQL配置工具,发现SQL服务显示远程调用过程失败(相关搜索:防火墙)
  • ¥15 eNSP中基于默认路由及浮动路由的公司与分部互联和校园网综合项目
  • ¥15 主要进行描述泥浆在管路不同区段泥浆的密度不相同,泥浆的密度有高有低,此时管路的摩阻分布需要怎么计算,(标签-matlab)
  • ¥40 通过编制程序计算圆管内层流充分发展对流换热,参数如图5-4,以及公式5-16所示,要求用表5-6对程序计算准确性进行验证
  • ¥20 该学习哪个编程语言? AI会取代程序员吗?
  • ¥15 ensp如何拼通IP地址
  • ¥15 saber软件导入Ibis模型报错