[英]Laravel post : routing issue
所以,我從laravel開始。 嘗試將表單發布到同一頁面。 這是我到目前為止的一切
routes.php文件
Route::get('/', 'HomeController@showWelcome');
Route::group(array('before' => 'csrf'), function () {
Route::post('contactus', 'HomeController@sendEmail');
});
hello.php
<?php echo Form::open(array('action' => 'HomeController@sendEmail'))?>
input fields here
<?php echo Form::close() ?>
HomeController的
public function showWelcome()
{
return View::make('hello');
}
public function sendEmail()
{
print_r($_POST);exit;
}
問題 :表格被發布到URL public / contactus
有人可以指出我在做什么真正愚蠢的事情嗎?
routes.php文件
Route::get('/', 'HomeController@showWelcome');
Route::post('/', array(
'before' => 'csrf', // csrf filter
'uses' => 'HomeController@sendEmail' // the controller action to be used
));
hello.php
<?php echo Form::open(array('action' => 'HomeController@sendEmail')) ?>
<!-- input fields here -->
<?php echo Form::close() ?>
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);
}
路線
Route::get('/', 'HomeController@showWelcome');
Route::post('/', 'HomeController@sendEmail');
Hello.blade.php
@if(isset($post))
{{$post}}
@endif
{{Form::open()}}
{{Form::text('sometext')}}
{{Form::close()}}
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.