Save Multi Rows


i have this in my controller :


$model = Naskah::model()->find('id_naskah='.$id_naskah);

  if(! empty($model)&&isset($_POST['Naskah']))


	$model->no_referensi = $model->no;

	$daftar_penerima = $_POST['Naskah']['daftar_penerima'];

	foreach($daftar_penerima as $id_penerima)


		$model=new Naskah;

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

	        $model->id_penerima = $id_penerima;








                                   (Yii::app()->basePath) . '/files/'.$file_name);






after submit in form, i want to save into multi rows in one table. how can i make it? help

up… help :unsure:

I don’t have deep knowledge about this but, for my requirement i have used like this to save multiple values in the table.

I’m saving the education table values based on the user id so i have created as follows:

My controller:

$id = isset($_GET['u']) ? base64_decode($_GET['u']) : null;

     $userModel= Users::model()->findByAttributes(array('id'=>$id));

     $userEducations = $userModel->usersEducations;

     if (isset($_POST['Users'])) {

          $userModel->attributes = $_POST['Users'];

          if (isset($_POST['UsersEducation'])) {

               foreach($_POST['UsersEducation'] as $i => $education) {

                   if (count($userEducations) <= $i) {

	               $userEducations[$i] = new UsersEducation;


 	           $userEducations[$i]->attributes = $education;

 	           $userEducations[$i]->user_id = $id;


              $isSaved = $userModel->save();

              if ($isSaved) {

		foreach($userEducations as $userEducation) {

		   $isSaved = $userEducation->save();

		   if (!$isSaved) {






And based on your requirements you can change my code.,


I don’t know how you manage to get multi rows from the view anyway dynamictabularform could you being of interest to you and I understand this can guide you.


P.D.: make use of this Multimodelform, to "Handling of multiple records and models in a form".

thank you very much…it SOLVED

That is great.

It would be excellent if you can share your solution here then other Yii user can find this post helpful. It’s always appreciated.