无法使用条件cakephp更新多个表格中的特定行

时间:2017-05-19 03:36:37

标签: php mysql cakephp

我有SubjectTutorTopicLessonQuestion个表格。每个表都有iduser_idnameschool_id列。

我想在user_id表中更新SubjectTutor的功能,该Topic.user_id将直接更新行Lesson.user_idQuestion.user_idSubjectTutor.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为空。

0 个答案:

没有答案