Save model in a loop


$model=new Room;

		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);











I have this code and I want to save multiple models in a loop

Someone to help me please

Like this?

or this?

It is not working. This is the view code:

$floors = Floor::model()->findByAttributes(array('id' => $_REQUEST['id']));

    for ($i = 0; $i < $floors->no_of_rooms; $i++) {

Kindly help

A basic loop would be something like the following

public function save($id){

  $floors = Floor::find()->where(['id' => $id]);

  foreach($floors as $floor){ 

   $model=new Room;

   $model->floor= $floor->id;




If it’s tabular input you should check out some of the widgets that handle this process completely.