[英]Laravel post : routing issue
So, i started with laravel. 所以,我从laravel开始。 Tried with making a form post to the same page.
尝试将表单发布到同一页面。 Here's what i have so far,
这是我到目前为止的一切
routes.php routes.php文件
Route::get('/', 'HomeController@showWelcome');
Route::group(array('before' => 'csrf'), function () {
Route::post('contactus', 'HomeController@sendEmail');
});
hello.php hello.php
<?php echo Form::open(array('action' => 'HomeController@sendEmail'))?>
input fields here
<?php echo Form::close() ?>
HomeController HomeController的
public function showWelcome()
{
return View::make('hello');
}
public function sendEmail()
{
print_r($_POST);exit;
}
Problem : Form gets posted to the url public/contactus 问题 :表格被发布到URL public / contactus
Can someone point out which really stupid thing, i am doing? 有人可以指出我在做什么真正愚蠢的事情吗?
routes.php routes.php文件
Route::get('/', 'HomeController@showWelcome');
Route::post('/', array(
'before' => 'csrf', // csrf filter
'uses' => 'HomeController@sendEmail' // the controller action to be used
));
hello.php hello.php
<?php echo Form::open(array('action' => 'HomeController@sendEmail')) ?>
<!-- input fields here -->
<?php echo Form::close() ?>
HomeController.php HomeController.php
Public function showWelcome()
{
return View::make('hello');
}
public function sendEmail()
{
$data = Input::all();
print_r($data);
// return the same view but with posted fields in the $data array
return View::make('hello', $data);
}
Routes 路线
Route::get('/', 'HomeController@showWelcome');
Route::post('/', 'HomeController@sendEmail');
Hello.blade.php Hello.blade.php
@if(isset($post))
{{$post}}
@endif
{{Form::open()}}
{{Form::text('sometext')}}
{{Form::close()}}
HomeController HomeController的
Public function showWelcome()
{
return View::make('hello');
}
public function sendEmail()
{
$post = Input::all();
return View::make('hello', array('post' => $post));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.