Hello ,I’m a newbie in yii.I want to pass array of object modle from controller to to view.This is my code
public function actionCreate() {
if (isset($_GET['productId']) && isset($_GET['categoryId'])) {
$countProperty = CategoryProperty::model()->count('categoryId=:categoryId', array(':categoryId' => $_GET['categoryId']));
$model=array();
for($i=0;$i<$countProperty;$i++){
[size="4"][b] $model[] = new Productproperty;[/b][/size]
}
if (isset($_POST['Productproperty'])) {
for($i=0;$i<$countProperty;$i++){
$model[$i]->attributes = $_POST['Productproperty'];
}
var_dump($_POST);
exit();
if ($model->save())
$this->redirect(array('view', 'id' => $model->propertyId));
}
[color="#FF0000"]$this->render('create', array(
'model' => $model,'countp'=>$countProperty
));[/color]
}
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
}
This a view ----------------------------------------------------------------
<?php $form=$this->beginWidget(‘CActiveForm’, array(
'id'=>'productproperty-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
[color="#9ACD32"]<?php for($i=0;$i<$countp;$i++){?>
<div class="row">
<?php echo $form->labelEx($model[$i],'value'); ?>
<?php echo $form->textField($model[$i],'value',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model[$i],'value'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model[$i],'unit'); ?>
<?php echo $form->textField($model[$i],'unit',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($model[$i],'unit'); ?>
</div>
<?php }?>[/color]
<div class="row buttons">
<?php echo CHtml::submitButton("Create"); ?>
</div>
<?php $this->endWidget(); ?>
but I var_dump($_POST) in controller when view submit ,It only get the last object model in array.
Please help me.
Thanks you very much