Laravel 4 表单发布
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20340142/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 4 Form Post
提问by WebDevB
Im currently in the process of learning Laravel 4.
我目前正在学习 Laravel 4。
I'm trying to create a really simple post form, here is my code for the opening of the form:
我正在尝试创建一个非常简单的帖子表单,这是我打开表单的代码:
{{ Form::open(array('post' => 'NewQuoteController@quote')) }}
And then within my NewQuoteController i have the following:
然后在我的 NewQuoteController 中,我有以下内容:
public function quote() {
$name = Input::post('ent_mileage');
return $name;
}
I keep getting the following error:
我不断收到以下错误:
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
It's probably something really stupid... Thanks.
这可能是非常愚蠢的事情......谢谢。
EDIT
编辑
This is what I have in my routes.php
这就是我在 routes.php 中的内容
Route::get('/newquote','NewQuoteController@vehicledetails');
Route::post('/newquote/quote', 'NewQuoteController@quote');
回答by Antonio Carlos Ribeiro
For POST looks like you need to change it to:
对于 POST 看起来您需要将其更改为:
{{ Form::open(array('action' => 'NewQuoteController@quote')) }}
And you need to have a route to your controller action:
并且您需要有一条通往控制器操作的路线:
Route::post('quote', 'NewQuoteController@quote');
Default method for Form::open()
is POST, but if you need to change it to PUT, for example, you will have to
默认方法Form::open()
是 POST,但如果你需要将其更改为 PUT,例如,你将不得不
{{ Form::open(array('method' => 'PUT', 'action' => 'NewQuoteController@quote')) }}
And you'll have to create a new route for it too:
您还必须为它创建一条新路线:
Route::put('quote', 'NewQuoteController@quote');
You also have to chage
你也必须改变
$name = Input::post('ent_mileage');
to
到
$name = Input::get('ent_mileage');
You can use the same url for the different methods and actions:
您可以对不同的方法和操作使用相同的 url:
Route::get('/newquote','NewQuoteController@vehicledetails');
Route::post('/newquote', 'NewQuoteController@quote');
Route::put('/newquote', 'NewQuoteController@quoteUpdate');
回答by David Donovan
Have you tried changing your form open to
您是否尝试过将表单更改为
{{Form::open(['method'=>'POST', 'route' =>'NewQuoteController@quote')}}
and in your controller access the form input using one of the Input methods ?
并在您的控制器中使用其中一种输入方法访问表单输入?
public function quote() {
$name = Input::get('ent_mileage');
return $name;
}