问题描述
我正在尝试一些非常基本的操作.我已经习惯了CI,现在正在学习Laravel 4,他们的文档并不容易!无论如何,我试图创建一个登录表单,并通过在下一个表单中打印数据来确保成功发布了数据.我收到此异常:
I am trying to get something very basic running. I am used to CI and now learning Laravel 4, and their docs are not making it easy! Anyways, I am trying to create a login form and just make sure that data is posted successfully by printing it in the next form. I am getting this exception:
和我的MemberController.php:
and my MemberController.php:
public function index()
{
if (Session::has('userToken'))
{
/*Retrieve data of user from DB using token & Load view*/
return View::make('members/profile');
}else{
return View::make('members/login');
}
}
public function validateCredentials()
{
if(Input::post())
{
$email = Input::post('email');
$password = Input::post('password');
return "Email: " . $email . " and Password: " . $password;
}else{
return View::make('members/login');
}
}
且路线具有:
Route::get('/', function()
{
return View::make('hello');
});
Route::get('/members', 'MemberController@index');
Route::get('/validate', 'MemberController@validateCredentials');
最后我的视图login.php具有以下表单方向:
and finally my view login.php has this form direction:
<?php echo Form::open(array('action' => 'MemberController@validateCredentials')); ?>
任何帮助将不胜感激.
推荐答案
由于发布到GET
路由,因此出现了该错误.
You are getting that error because you are posting to a GET
route.
我会将您的validate
路由分为单独的GET
和POST
路由.
I would split your routing for validate
into a separate GET
and POST
routes.
新路线:
Route::post('validate', 'MemberController@validateCredentials');
Route::get('validate', function () {
return View::make('members/login');
});
那么您的控制器方法就可以了
Then your controller method could just be
public function validateCredentials()
{
$email = Input::post('email');
$password = Input::post('password');
return "Email: " . $email . " and Password: " . $password;
}
这篇关于laravel抛出MethodNotAllowedHttpException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!