In CakePHP when I save the data with the below code, I get the data being saved as expected but I get all the data saved 2 times. The $lesson
data variable does not retrieve 2 copies of the data so the save function is the problem. I tried using save in a loop and that gives the same problem. There must be something simple I am doing wrong.
$data=array();
$i=0;
$this->Lessondata->cacheQueries = false;
$this->Lessondata->create( );
foreach ($lessons as $item):
// $this->Lessondata->cacheQueries = false;
$data[$i]['Lessondata']['lesson_id']=$item['Lesson']['id'];
$data[$i]['Lessondata']['st_id']=$item['Student']['id'];
$data[$i]['Lessondata']['tutor_id']=$item['Tutor']['id'];
$data[$i]['Lessondata']['student_name']=$item['Student']['first_name'].' '.$item['Student']['last_name'];
$data[$i]['Lessondata']['subject']=$item['Subject']['name'];
$data[$i]['Lessondata']['tutor_name']=$item['Tutor']['first_name'].' '.$item['Tutor']['last_name'];
$data[$i]['Lessondata']['class_year']=$item['Student']['class_year'];
// debug($data[$i]);
debug($i);
$i=$i+1;
endforeach;
$this->Lessondata->saveAll($data);
$data['Lessondata'][$i]['lesson_id']
etc – Salines