【问题标题】:handleRoutingException error when routing restful controllers路由restful控制器时出现handleRoutingException错误
【发布时间】:2013-06-22 10:58:22
【问题描述】:

我对 laravel 还很陌生,我遇到了路由问题

在我的 routes.php 中

Route::controller('users', 'userController');

我的控制器目录中有一个名为 userController.php 的文件

用户控制器:

<?php

class userController extends BaseController {
public $restful = true ;


    public function index()
    {
        echo 'hello';
    }
    public function check()
    {
        echo 'check';
    }
}

当我运行http://localhost/larave/public/users

我收到NotFoundHttpException

Symfony\Component\HttpKernel\Exception\NotFoundHttpException
…\bootstrap\compiled.php4921
Illuminate\Routing\Router handleRoutingException
…\bootstrap\compiled.php4766
Illuminate\Routing\Router findRoute
…\bootstrap\compiled.php4754
Illuminate\Routing\Router dispatch
…\bootstrap\compiled.php481
Illuminate\Foundation\Application dispatch
…\bootstrap\compiled.php470
Illuminate\Foundation\Application run
…\public\index.php49

怎么了?当我为每个控制器/动作进行路由时,它工作正常

Route::get('users/check', 'userController@check');

【问题讨论】:

  • 您将其标记为 laravel 和 laravel 4.. 您使用的是什么版本?

标签: laravel laravel-4


【解决方案1】:

RESTful 控制器方法需要以 HTTP VERB.. 作为前缀,例如 getpost

例子:

class userController extends BaseController {
  public function getIndex() {
    return "I am echoing only when you GET me!";
  }

  public function postIndex() {
    return "I am echoing only when you POST to me!";
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-24
    • 2012-12-24
    • 1970-01-01
    • 1970-01-01
    • 2016-08-08
    • 1970-01-01
    • 2013-06-09
    • 2013-06-04
    相关资源
    最近更新 更多