У меня есть это сообщение, когда вы пытаетесь запустить любой контроллер
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
- Маршрут контроллера не найден в Laravel 4
- как изменить маршруты в codeigniter
- Несколько шаблонов в одиночной маршрутизации symfony
- Regex - греческие символы в URL-адресе
- cakephp 3 параметр url
Метод контроллера не найден.
У меня есть этот код в файле маршрута
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 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 Я запускаю эту команду
php artisan routes
+ -------- + ---------------------------------------- -------------------- + ------ + ---------------------- --------- + ---------------- + --------------- + | Домен | URI | Имя | Действие | Перед фильтрами | После фильтров | + -------- + ---------------------------------------- -------------------- + ------ + ---------------------- --------- + ---------------- + --------------- + | | GET index / {one?} / {Two?} / {Three?} / {Four?} / {Five?} | | HomeController @ getIndex | | | | | GET / | | HomeController @ getIndex | | | | | GET {_missing} | | HomeController @ missingMethod | | | | | GET users / index / {one?} / {Two?} / {Three?} / {Four?} / {Five?} | | ПользователиController @ getIndex | | | | | GET пользователей | | ПользователиController @ getIndex | | | | | GET users / register / {one?} / {Two?} / {Three?} / {Four?} / {Five?} | | ПользователиController @ getRegister | | | | | Пользователи POST / create / {one?} / {Two?} / {Three?} / {Four?} / {Five?} | | ПользователиController @ postCreate | | | | | GET users / login / {one?} / {Two?} / {Three?} / {Four?} / {Five?} | | ПользователиController @ getLogin | | | | | Пользователи POST / signin / {one?} / {Two?} / {Three?} / {Four?} / {Five?} | | ПользователиController @ postSignin | | | | | GET users / dashboard / {one?} / {Two?} / {Three?} / {Four?} / {Five?} | | ПользователиController @ getDashboard | | | | | GET users / logout / {one?} / {Two?} / {Three?} / {Four?} / {Five?} | | ПользователиController @ getLogout | | | | | GET users / {_ missing} | | ПользователиController @ missingMethod | | | + -------- + ---------------------------------------- -------------------- + ------ + ---------------------- --------- + ---------------- + --------------- +
whine я пытаюсь получить доступ к localhost:8000/users/login
или любой метод на любом контроллере, это сообщение появляется
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException Controller method not found.
Попробуйте изменить порядок регистрации маршрута
Route::controller("users","UsersController"); Route::controller("/","HomeController");