2014-02-11 3 views
8

У меня есть это сообщение скулить пытается запустить любой контроллерметод контроллера не найден - Laravel 4

Symfony \ Component \ HttpKernel \ Exception \ 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

Спасибо очень много ... вы great man – Ahmed

+0

Это сработало и для меня, вы не разделяете, почему так работает? – Gideon

+4

Маршруты регистрируются сверху вниз. Если найдено совпадение, соответствующий ответный вызов выполняется, Laravel не продолжается в поиске. Домашний маршрут ''/"' должен быть помещен как последний, так как это говорит о том, что искать больше нечего. – Andreyco

Смежные вопросы