0

我必须在数据库中的表中输入几个字符串。它的表格输入 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;?>

请帮忙

4

1 回答 1

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 ($_POST), object 使其更容易查看。

于 2013-04-02T01:29:29.947 回答