2014-02-11 53 views
8

我有此消息抱怨试图运行任何控制器控制器方法未发现 - laravel 4

的Symfony \元器件\ HttpKernel \异常\ NotFoundHttpException

控制器方法没有找到。

我有这样的代码在我的路线文件

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?}   |  | [email protected]  |    |    | 
|  | GET/             |  | [email protected]  |    |    | 
|  | GET {_missing}            |  | [email protected] |    |    | 
|  | GET users/index/{one?}/{two?}/{three?}/{four?}/{five?}  |  | [email protected]  |    |    | 
|  | GET users             |  | [email protected]  |    |    | 
|  | GET users/register/{one?}/{two?}/{three?}/{four?}/{five?} |  | [email protected] |    |    | 
|  | POST users/create/{one?}/{two?}/{three?}/{four?}/{five?} |  | [email protected] |    |    | 
|  | GET users/login/{one?}/{two?}/{three?}/{four?}/{five?}  |  | [email protected]  |    |    | 
|  | POST users/signin/{one?}/{two?}/{three?}/{four?}/{five?} |  | [email protected] |    |    | 
|  | GET users/dashboard/{one?}/{two?}/{three?}/{four?}/{five?} |  | [email protected] |    |    | 
|  | GET users/logout/{one?}/{two?}/{three?}/{four?}/{five?} |  | [email protected]  |    |    | 
|  | GET users/{_missing}          |  | [email protected] |    |    | 
+--------+------------------------------------------------------------+------+-------------------------------+----------------+---------------+ 

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

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException 

Controller method not found. 

回答

17

尝试改变路线注册

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

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

非常感谢您的秩序......你是伟大的人 – Ahmed

+0

这也适用于我,你介意为什么这样工作吗? – Gideon

+4

路由从顶部到底部注册。如果发现任何匹配,则执行匹配的回调,Laravel不会继续查找。 Home路由''/“'应该放在最后一个,因为这表示没有更多的东西要查找。 – Andreyco