微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 找不到控制器方法 – laravel 4

我有这条消息,试图运行任何控制器

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

Controller method not found.

我的Route文件中有此代码

Route::controller("/","HomeController");

Route::controller("users","UsersController");

和我的控制器中的代码

<?PHP

class UsersController extends BaseController
{

    protected $layout = "layouts.main";

    public function __construct()
    {
        $this->beforeFilter('csrf',array('on' => 'post'));
        $this->beforeFilter('auth',array('only' => array('getDashboard')));
    }

    public function getIndex()
    {
       return Redirect::to("users/register");
    }

    public function getRegister()
    {
        $this->layout->content = View::make('users.register');
    }


    public function postCreate()
    {
        $validator = Validator::make(Input::all(),User::$rules);
        if ($validator->passes()) {
            // validation has passed,save user in DB
            $user = new User;
            $user->firstname = Input::get('firstname');
            $user->lastname = Input::get('lastname');
            $user->email = Input::get('email');
            $user->password = Hash::make(Input::get('password'));
            $user->save();

            return Redirect::to('users/login')->with('message','Thanks for registering!');
        } else {
            return Redirect::to('users/register')->with('message','The following errors occurred')->withErrors($validator)->withinput();
        }
    }

    function getLogin()
    {
        if (Auth::check()) return Redirect::to("users/dashboard")->with('message','Thanks for registering!');

        $this->layout->content = View::make("users.login");
    }

    function postSignin()
    {
        if (Auth::attempt(array('email' => Input::get('email'),'password' => Input::get('password')))) {
            return Redirect::to('users/dashboard')->with('message','You are Now logged in!');
        } else {
            return Redirect::to('users/login')
                ->with('message','Your username/password combination was incorrect')
                ->withinput();
        }
    }

    public function getDashboard()
    {
        $this->layout->content = View::make("users.dashbord");
    }

    public function getlogout()
    {
        Auth::logout();
        return Redirect::to('users/login')->with('message','Your are Now logged out!');
    }

我跑这个命令的呜咽

PHP artisan routes
+--------+------------------------------------------------------------+------+-------------------------------+----------------+---------------+
| Domain | URI                                                        | Name | Action                        | Before Filters | After Filters |
+--------+------------------------------------------------------------+------+-------------------------------+----------------+---------------+
|        | GET index/{one?}/{two?}/{three?}/{four?}/{five?}           |      | HomeController@getIndex       |                |               |
|        | GET /                                                      |      | HomeController@getIndex       |                |               |
|        | GET {_missing}                                             |      | HomeController@missingMethod  |                |               |
|        | GET users/index/{one?}/{two?}/{three?}/{four?}/{five?}     |      | UsersController@getIndex      |                |               |
|        | GET users                                                  |      | UsersController@getIndex      |                |               |
|        | GET users/register/{one?}/{two?}/{three?}/{four?}/{five?}  |      | UsersController@getRegister   |                |               |
|        | POST users/create/{one?}/{two?}/{three?}/{four?}/{five?}   |      | UsersController@postCreate    |                |               |
|        | GET users/login/{one?}/{two?}/{three?}/{four?}/{five?}     |      | UsersController@getLogin      |                |               |
|        | POST users/signin/{one?}/{two?}/{three?}/{four?}/{five?}   |      | UsersController@postSignin    |                |               |
|        | GET users/dashboard/{one?}/{two?}/{three?}/{four?}/{five?} |      | UsersController@getDashboard  |                |               |
|        | GET users/logout/{one?}/{two?}/{three?}/{four?}/{five?}    |      | UsersController@getlogout     |                |               |
|        | GET users/{_missing}                                       |      | UsersController@missingMethod |                |               |
+--------+------------------------------------------------------------+------+-------------------------------+----------------+---------------+

我试图访问localhost:8000 / users / login或任何控制器中的任何方法
出现此消息

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

Controller method not found.
尝试更改路线注册的顺序
Route::controller("users","UsersController");

Route::controller("/","HomeController");

原文地址:https://www.jb51.cc/laravel/138094.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。