How To Save The Same Model Multiple Times


(Subhash 5c3) #1

Here i am saving the same model multiple times depending upon the user . I kept two fields one is title and text

and if user click add button then another two fields will added and soon but while i am saving these models in the controller i able to save the last fields only

my controller is

if (isset($_POST[‘Task’]))

	{


		


		foreach($_POST['Task'] as $i => $item)


		{


			$model->attributes = $_POST['Task'][$i];


			print_r($model->attributes);


			//$model->save();


		}


		


	}

and while print the array using print_r() it is getting all the fields value ex

Array ( [title] => title1 [id] => [text] => ) Array ( [title] => title1 [text] => text1 [id] => ) Array ( [title] => title4 [text] => text1 [id] => ) Array ( [title] => title4 [text] => text4 [id] => )

can anyone help me in saving all these values


(Sharmakiran71) #2

This two links might be useful…

Wiki article

Guide topic