2013-04-01 91 views
0

我必須在db中輸入幾個字符串到表中。它的表格輸入yii。無法理解,怎麼做這種方式,如果我有這樣的控制器:表格輸入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;?> 

請幫助

回答

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),對象使它更容易看到。