找不到控制器方法 - laravel 4

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

问题描述

我有这个消息抱怨试图运行任何控制器

<块引用>

SymfonyComponentHttpKernelExceptionNotFoundHttpException

找不到控制器方法.

我的路线文件中有此代码

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

我的控制器中的这段代码

 <?php类 UsersController 扩展 BaseController{受保护的 $layout = "layouts.main";公共函数 __construct(){$this->beforeFilter('csrf', array('on' => 'post'));$this->beforeFilter('auth', array('only' => array('getDashboard')));}公共函数 getIndex(){return Redirect::to(用户/注册");}公共函数 getRegister(){$this->layout->content = View::make('users.register');}公共函数 postCreate(){$validator = Validator::make(Input::all(), User::$rules);if ($validator->passes()) {//验证通过,将用户存入数据库$user = 新用户;$user->firstname = Input::get('firstname');$user->lastname = Input::get('lastname');$user->email = 输入::get('email');$user->password = Hash::make(Input::get('password'));$user->save();return Redirect::to('users/login')->with('message', '感谢注册!');} 别的 {return Redirect::to('users/register')->with('message', '发生以下错误')->withErrors($validator)->withInput();}}函数获取登录(){if (Auth::check()) return Redirect::to("users/dashboard")->with('message', '感谢注册!');$this->layout->content = View::make("users.login");}函数 postSignin(){if (Auth::attempt(array('email' => Input::get('email'), 'password' => Input::get('password')))) {return Redirect::to('users/dashboard')->with('message', '你现在登录了!');} 别的 {返回重定向::to('用户/登录')->with('message', '您的用户名/密码组合不正确')->withInput();}}公共函数 getDashboard(){$this->layout->content = View::make("users.dashbord");}公共函数 getLogout(){验证::注销();return Redirect::to('users/login')->with('message', '你现在已经登出!');}

我运行这个命令

php 工匠路线

<上一页>+--------+------------------------------------------------------------+------+-------------------+----------------+----------------+|域名 |网址 |姓名 |行动 |过滤器前 |后过滤器 |+--------+------------------------------------------------------------+------+-------------------+----------------+----------------+||GET 索引/{一个?}/{两个?}/{三个?}/{四个?}/{五个?} ||HomeController@getIndex |||||获取/||HomeController@getIndex |||||获取 {_missing} ||HomeController@missingMethod |||||GET 用户/索引/{一个?}/{两个?}/{三个?}/{四个?}/{五个?} ||用户控制器@getIndex |||||获取用户 ||用户控制器@getIndex |||||GET 用户/注册/{一个?}/{两个?}/{三个?}/{四个?}/{五个?} ||用户控制器@getRegister |||||POST 用户/创建/{一个?}/{两个?}/{三个?}/{四个?}/{五个?} ||用户控制器@postCreate |||||GET users/login/{one?}/{two?}/{three?}/{four?}/{five?} ||用户控制器@getLogin |||||POST users/signin/{one?}/{two?}/{three?}/{four?}/{five?} ||用户控制器@postSignin |||||GET users/dashboard/{one?}/{two?}/{three?}/{four?}/{five?} ||用户控制器@getDashboard |||||GET users/logout/{one?}/{two?}/{three?}/{four?}/{five?} ||用户控制器@getLogout |||||获取用户/{_missing} ||用户控制器@missingMethod |||+--------+------------------------------------------------------------+------+-------------------+----------------+----------------+

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

SymfonyComponentHttpKernelExceptionNotFoundHttpException找不到控制器方法.

解决方案

尝试改变路由注册的顺序

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

I have this message whine trying to run any controller

Symfony Component HttpKernel Exception NotFoundHttpException

Controller method not found.

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!');
    }

 

Whine I run this Command

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 |                |               |
+--------+------------------------------------------------------------+------+-------------------------------+----------------+---------------+

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)