【问题标题】:Undefined variable in select when submitting form in Laravel 4在 Laravel 4 中提交表单时选择中未定义的变量
【发布时间】:2013-08-25 09:12:37
【问题描述】:

我正在尝试从表中提取数据,使用该数据填充选择输入,然后将该信息(和其他信息)发布到另一个表。呈现视图时,它会使用所需数据正确填充选择,但是当我提交表单时,我收到未定义变量错误。

Undefined variable: secondarygenre

查看

{{ Form::select('genre', $secondarygenre, null, array('class' => 'form-control', 'id' => 'genre')) }}

控制器

//Data is passed to the form in the view
public function addSubmission() {

    $secondarygenre = Genre::lists('friendlyName', 'id');

    return View::make('add')
        ->with('secondarygenre', $secondarygenre);
}

//Form is submitted
public function successfulSubmission() {

$track = new Track();
$track->genre_id = Input::get('genre');
$track->save();

}

如果它用数据填充选择输入,我知道它的变量不是未定义的。

如果我遗漏了什么,我深表歉意,这是我第一个使用 Laravel(或任何 MVC 框架)的项目。

任何帮助将不胜感激!

【问题讨论】:

    标签: php forms laravel undefined


    【解决方案1】:

    在帖子中,您还必须返回带有变量的视图,看起来您只使用 get 执行此操作,但您需要为每个使用 ->with('secondarygenre', $sg) 一次请求类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-16
      • 2021-12-27
      • 2014-04-28
      • 1970-01-01
      • 2016-01-16
      • 1970-01-01
      • 2013-07-21
      • 2014-09-11
      相关资源
      最近更新 更多