Only last element of array getting inserted in the table

Hi,

I am using jappendo to get multiple copies of rows.

I am not able to inert all the entries into the table. Only the last row is getting inserted. Can anybody tell me what is wrong with my code.

The following is my controller code:


public function actionCreate()

	{

		$model=new BusType;

         $model2=new BusProducts;

		// Uncomment the following line if AJAX validation is needed

 $this->performAjaxValidation($model);

 //Get the number of models you will be working with 

$maxRows =count($model2->cat_id=$_POST['cat_id']);


		if(isset($_POST['BusType']))

		{

			$model->attributes=$_POST['BusType'];

				$model2->attributes=$_POST['BusProducts'];

			

			if($model->save())

				{

					

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

            { $model2->bus_type_id = $model->bus_type_id;

				

					   $model2->quantity = $_POST['quantity'][$i]; 

					    $model2->cat_id =$_POST['cat_id'][$i];

						 $model2->subcat_id = $_POST['subcat_id'][$i]; 


										$model2->save();  

							}

				$this->redirect(array('view','id'=>$model->bus_type_id));

		}

		}


		$this->render('create',array(

			'model'=>$model,

			'model2'=>$model2,

		));

	}