表格输入Yii

时间:2013-04-01 20:00:45

标签: php yii tabular-form

我必须在db中输入几个字符串到表中。表格输入yii。无法理解,怎么做这种方式,如果我有这样的控制器:

public function actionCreate()
{
    $model1=new Section;
            $model2=new SectionI18n;           
if(isset($_POST['SectionI18n'])){
   foreach ($model2 as $i => $m1) {
         foreach($_POST['SectionI18n'] as $i => $m1)
      {
                $m1=new SectionI18n;
                $m1->attributes=$_POST['SectionI18n'][$i];
                $my[]=$m1->attributes;
              }
}

和一些布局:

<?php foreach ($model2 as $i=>$m1):?>
<?php  ?>
<div class="row">
    <?php echo $form->labelEx($model2,'Название'); ?>
    <?php echo $form->textField($model2,'[$i]title',array('size'=>60,'maxlength'=>100)); ?>
    <?php echo $form->error($model2,'title'); ?>
</div>

<div class="row">
    <?php echo $form->labelEx($model2,'Описание'); ?>
    <?php echo $form->textArea($model2,'[$i]description',array('size'=>60,'maxlength'=>200)); ?>
    <?php echo $form->error($model2,'description'); ?>
</div>

<div class="row">
    <?php echo $form->labelEx($model2,'Язык'); ?>
    <?php echo $form->dropDownList($model2,'[$i]lang',array('ru'=>'ru','en'=>'en','ua'=>'ua')); ?>
    <?php echo $form->error($model2,'lang'); ?>
</div>
<?php ?>
<?php endforeach;?>

请帮助

1 个答案:

答案 0 :(得分:0)

这与此类似:

foreach ( $_POST[Model Name] as $i => $y ){
   $var name[$i] = new Model Name;
   $var name[$i]->title = $_POST[Model Name][$i][title]
   ...
}

var_dump帖子($ _POST),对象让人们更容易看到。