//在 controller 里面 $model=new Person; /* $addrs 存储 Addr model 的数组,放几个你就看着办吧*/ $addrs = array(); if(isset($_POST['Person'])) { $model->attributes = $_POST['Person']; /*此处省略一堆逻辑*/ foreach($_POST['Addr'] as $one_addr) { $addr = new Addr(); $addr->attributes = $one_addr; /*此处省略另一堆逻辑*/ } } $this->render('create',array( 'model'=>$model, 'addrs' => $addrs, )); //在 view 里面 /*可以循环输出你的多个 model */ $num = count($addrs); for($i = 0;$i < $num;++$i) { echo $form->labelEx($addrs[$i],"[{$i}]postcode"); echo $form->textField($addrs[$i],"[{$i}]postcode",array('size'=>10,'maxlength'=>10)); ...; } /*也可以通过数字指定输出某个 model */ echo $form->labelEx($addrs[0],"[0]postcode"); echo $form->textField($addrs[0],"[0]postcode",array('size'=>10,'maxlength'=>10));
您可能感兴趣的文章: