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.
非常感謝您的秩序......你是偉大的人 – Ahmed
這也適用於我,你介意爲什麼這樣工作嗎? – Gideon
路由從頂部到底部註冊。如果發現任何匹配,則執行匹配的回調,Laravel不會繼續查找。 Home路由''/「'應該放在最後一個,因爲這表示沒有更多的東西要查找。 – Andreyco