找不到控制器方法-Laravel 4 [英] Controller method not found - laravel 4

查看:138
本文介绍了找不到控制器方法-Laravel 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试运行任何控制器时听到此消息

I have this message whine trying to run any controller

Symfony \组件\ HttpKernel \ Exception \ NotFoundHttpException

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

找不到控制器方法.

我的路线文件中有此代码

I have this Code in my Route file

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

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

以及此代码在我的控制器中

and this code in my Controller

 <?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或任何控制器中的任何方法时 此消息出现

whine i trying to access to localhost:8000/users/login or any method in any controller this message appear

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

Controller method not found.

推荐答案

尝试更改路线注册的顺序

Try to change order of route registration

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

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

这篇关于找不到控制器方法-Laravel 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆