How To Create Model Iteratively.

Hi there, as a beginner in Yii i have a question that I want to create models in iteration. For example I want to create result model for 30 students. How to create these models in iteration? I cant hardcode becaue number students may vary from class to class.

In this approach i need to use tabular input but for that purpose i need to bind each model`s attribute to some element like


textArea 

Definitive guide presents this code


<div class="form">

<?php echo CHtml::beginForm(); ?>

<table>

<tr><th>Name</th><th>Price</th><th>Count</th><th>Description</th></tr>

<?php foreach($items as $i=>$item): ?>

<tr>

<td><?php echo CHtml::activeTextField($item,"[$i]name"); ?></td>

<td><?php echo CHtml::activeTextField($item,"[$i]price"); ?></td>

<td><?php echo CHtml::activeTextField($item,"[$i]count"); ?></td>

<td><?php echo CHtml::activeTextArea($item,"[$i]description"); ?></td>

</tr>

<?php endforeach; ?>

</table>

 

<?php echo CHtml::submitButton('Save'); ?>

<?php echo CHtml::endForm(); ?>

</div><!-- form -->

But how can i populate my array with distinct model names like model1,model2,model3 and so on, in iteration?

thanks

no need to change the model names to model1, model2 etc just declare the models as array and send to the view then iterate the models like




//in controller

$models = array();

$totalStudents=5;

for($i = 0; $i < $totalStudents; $i++)

{

 $models[$i] = new Student();

}


// do something ex check for students form posted or something


$this->render('view',array('items'=>$models));




// in view do like the same you posted previously