【问题标题】:Laravel 4 Form PostLaravel 4 表单发布
【发布时间】:2013-12-18 20:38:52
【问题描述】:

我目前正在学习 Laravel 4。

我正在尝试创建一个非常简单的帖子表单,这是我打开表单的代码:

{{ Form::open(array('post' => 'NewQuoteController@quote')) }}

然后在我的 NewQuoteController 中,我有以下内容:

public function quote() {

   $name = Input::post('ent_mileage');
   return $name;

}

我不断收到以下错误:

Symfony\Component\HttpKernel\Exception\NotFoundHttpException

这可能真的很愚蠢......谢谢。

编辑

这就是我的 routes.php 中的内容

Route::get('/newquote','NewQuoteController@vehicledetails');

Route::post('/newquote/quote', 'NewQuoteController@quote');

【问题讨论】:

    标签: php laravel laravel-4


    【解决方案1】:

    对于 POST 看起来您需要将其更改为:

    {{ Form::open(array('action' => 'NewQuoteController@quote')) }}
    

    而且你需要有一个路由到你的控制器动作:

    Route::post('quote', 'NewQuoteController@quote');
    

    Form::open() 的默认方法是 POST,但如果您需要将其更改为 PUT,例如,您将不得不

    {{ Form::open(array('method' => 'PUT', 'action' => 'NewQuoteController@quote')) }}
    

    您还必须为其创建一条新路线:

    Route::put('quote', 'NewQuoteController@quote');
    

    你也得追赶

    $name = Input::post('ent_mileage');
    

    $name = Input::get('ent_mileage');
    

    您可以为不同的方法和操作使用相同的 url:

    Route::get('/newquote','NewQuoteController@vehicledetails');
    
    Route::post('/newquote', 'NewQuoteController@quote');
    
    Route::put('/newquote', 'NewQuoteController@quoteUpdate');
    

    【讨论】:

    • 还是一样,我忘了添加我提交表单时收到此消息...
    • 使用路线时您也会收到此错误吗?检查生成的 HTML。获取
      行并粘贴它,或编辑您的消息。
    • NotFoundHttpException 是找不到路由错误。因此,您的 open() 必须生成与您所拥有的路线不同的路线。你能粘贴你的 HTML
      行吗?
    • localhost:8888/l4_site/public/newquote/quote" accept-charset="UTF-8">
    • PUT?你是在做 POST 还是 PUT?
    【解决方案2】:

    您是否尝试过将表单打开更改为

    {{Form::open(['method'=>'POST', 'route' =>'NewQuoteController@quote')}}
    

    并在您的控制器中使用输入方法之一访问表单输入?

    public function quote() {
    
        $name = Input::get('ent_mileage');
    
        return $name; 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-08
      • 2018-10-08
      • 2021-03-01
      • 2014-08-27
      • 2013-07-04
      • 1970-01-01
      • 2020-10-25
      • 1970-01-01
      相关资源
      最近更新 更多