How to save multiple row at once in cakephp

Cakephp

Posted on 18 Dec 15 by Vickey
  392



Some times we have a php array and we need to insert these value in a different row in a table for example I have an days array

$days=array('sunday','monday','tuesday');

and I want to insert these values in a different row with cakephp. For simple way i will use

foreach($days as $values)  {

	$data['Mymodel']['day']=$values;
	$this->Mymodel->create();
	$this->Mymodel->saveAll($data);
	
}

In this code each row insert with a different query but we do this at once in cakephp

foreach($days as $values)  {

     $data[]=array('day'=>$values);

}
$this->Mymodel->create();
$this->Mymodel->saveAll($data);

 


If this post help you reduce time to develop, you can help me to maintain this website :)
www.000webhost.com