我有SubjectTutor
,Topic
,Lesson
和Question
个表格。每个表都有id
,user_id
,name
和school_id
列。
我想在user_id
表中更新SubjectTutor
的功能,该Topic.user_id
将直接更新行Lesson.user_id
,Question.user_id
和SubjectTutor.user_id
{{1} }。
这是要更新SubjectTutor.user_id
的ctp文件:
<label for="exampleInputPassword1"> Select Tutor</label>
<?php echo($this->Form->input('SubjectTutor.user_id', array('options'=>$tutors,'div'=>false, 'label'=>false,
"class" => "form-control",'empty'=>'Select Tutor')));?>
</div>
这是控制器:
if ($this->request->is('post') || $this->request->is('put')) {
if (!empty($this->request->data)) {
if (!isset($this->request->params['_Token']['key']) || ($this->request->params['_Token']['key'] != $this->request->params['_Token']['key'])) {
$blackHoleCallback = $this->Security->blackHoleCallback;
$this->$blackHoleCallback();
}
//validate user data
$this->SubjectTutor->set($this->request->data['SubjectTutor']);
$this->SubjectTutor->setValidation('add');
if(isset($this->request->data['Plan']))
{
$this->SubjectTutor->Plan->set($this->request->data['Plan']);
$this->SubjectTutor->Plan->setValidation('add');
}
if ($this->SubjectTutor->validates()) {
if ($this->SubjectTutor->save($this->request->data['SubjectTutor'],false)) {
$subject_tutor_id = $id;
$tutor_ids = $this->SubjectTutor->user_id;
$school_ids = $this->SubjectTutor->school_id;
$this->Topic->updateAll(array('user_id'=>$tutor_ids), array('Topic.school_id'=>$school_ids));
$this->Lesson->updateAll(array('user_id'=>$tutor_ids), array('Lesson.school_id'=>$school_ids));
$this->Question->updateAll(array('user_id'=>$tutor_ids), array('Question.school_id'=>$school_ids));
$this->Session->setFlash("Record has been updated successfully", 'admin_flash_good');
$this->redirect(array('controller'=>'standards', 'action'=>'subject_list',$subject_detail['Subject']['standard_id']));
}
} else {
$this->Session->setFlash(__('The Subject could not be saved. Please, try again.', true), 'admin_flash_bad');
}
}
}
错误是:Topic.user_id,Lesson.user_id和Question.user_id不会更新。
我有调试$ tutor_ids,$ school_ids为空。