【发布时间】:2014-10-15 11:13:00
【问题描述】:
我在尝试将同名字段保存到新的单独记录时遇到问题。
似乎只将最后输入的字段(第二个输入)保存到新记录,而不是将第一个输入的字段保存到新记录。
我需要将两个输入的字段另存为新的单独记录
查看代码 -
<div class="row">
<div class="col-xs-12">
<div class="portlet box green">
<div class="portlet-title">
<div class="caption"><i class="fa fa-barcode"></i>Oven 1</div>
<div class="tools">
<a href class="collapse"></a>
</div>
</div>
<div class="portlet-body form">
<div class="form-body">
<div class="row">
<div class="col-xs-12 col-sm-3">
<div class="form-group">
<?php echo Form::label('height', 'height', array('class' => 'col-md-3 control-label')) ?>
<div class="col-md-9">
<?php echo Form::input('height[1]', $check->height, array('id' => 'height', 'class' => 'form-control')) ?>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="portlet-body form">
<div class="form-body">
<div class="row">
<div class="col-xs-12 col-sm-3">
<div class="form-group">
<?php echo Form::label('height', 'height', array('class' => 'col-md-3 control-label')) ?>
<div class="col-md-9">
<?php echo Form::input('height[2]', $check->height, array('id' => 'height', 'class' => 'form-control')) ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
控制器代码 -
public function action_clean()
{
$id = $this->request->param('id');
if ($_POST)
{
$check = $cat->height->find();
foreach($_POST['height'] as $key=>$value){
$check->height = $value;
}
$check->dt_logged = time();
$check->user_id = Auth::instance()->get_user()->id;
$check->cat = $cat->id;
$check->save();
echo json_encode(array('id' => $cat->id));
}
}
回顾一下,我需要将两个输入字段保存为新的单独记录
任何帮助将不胜感激。
干杯
【问题讨论】: