2014-10-02 3 views
0

cakephp에서 나는 하나의 테이블에서 반환 된 데이터를 다른 테이블에 저장할 수 없습니다. Tutors 테이블의 양식에 데이터가 미리 채워져 있습니다.이 데이터를 tutorEdit 테이블에 새 행으로 저장하면됩니다 (편집 기능과 혼동하지 않음). 내가 얻는 문제는 데이터를 저장하지만 tutorEdit는 반환 된 데이터를 저장하지 않는다는 것입니다 (오류 없음). 저장하고자하는 데이터가 'TutorEdit가', '교사'가 아니기 때문에 캔트 데이터를 1 테이블에서 다른 테이블로 저장

public function tutor_edit($id = null) { 
     $this->loadModel('Tutor'); 

     $this->Tutor->id = $id; 

     debug($this->request->data); 

     if (!$this->Tutor->exists()) { 
      throw new NotFoundException(__('Invalid tutor')); 
     } 
     if ($this->request->is('post') ) { 

      if ($this->TutorEdit->save($this->request->data)) { 
       $this->Session->setFlash(__('The tutor details to be edited have ben forwarded to management'), 'flash_success'); 
       // $this->redirect(array('controller'=> 'tutors' , 'action' => 'tutordetails')); 
      } else { 
       $this->Session->setFlash(__('The tutor edit details could not be saved. Please, try again.'), 'flash_alert'); 
      } 



     } else { 
      $this->request->data = $this->Tutor->read(null, $id); 
     } 

///// 
    <?php 
        echo $this->Form->create('Tutor',array('class' => 'form-horizontal')); 
        echo $this->Form->input('id', $formHorizontalHtmlOptions); 
        echo $this->Form->input('first_name', $formHorizontalHtmlOptions); 
        echo $this->Form->input('last_name', $formHorizontalHtmlOptions); 
        echo $this->Form->input('email', $formHorizontalHtmlOptions); 
        echo $this->Form->input('mobile', $formHorizontalHtmlOptions); 
        echo $this->Form->input('home_phone', $formHorizontalHtmlOptions); 
        echo $this->Form->input('work_phone', $formHorizontalHtmlOptions); 
        echo $this->Form->input('gender', array_merge($formHorizontalHtmlOptions, array('type' => 'select', 'options' => $gender))); 
        echo $this->Form->end('Save Edit Request'); 
        ?> 

http://book.cakephp.org/2.0/en/models/saving-your-data.html

답변

1

에서 이것에 대해 아무것도 볼 didnt한다. 공유 한 링크에서 첫 번째 섹션은 저장할 필요가있는 적절한 배열 형식을 보여줍니다.

이 시도 :

if ($this->request->is('post') ) { 
    $tutoredit = array('TutorEdit' => $this->request->data['Tutor']); 

    if ($this->TutorEdit->save($tutoredit)) { 
      $this->Session->setFlash(__('The tutor details to be edited have ben forwarded to management'), 'flash_success'); 
    } else { 
      $this->Session->setFlash(__('The tutor edit details could not be saved. Please, try again.'), 'flash_alert'); 
    } 
} 
+0

이 didnt 한 일을. 내가 dint는 오류가 발생하지만 요청 -> 데이터가 올바른 경우에도 데이터가 저장되지 않았다 – ajt

+0

게시물 대신 put으로 작동 했습니까? 또한 튜터 데이터뿐만 아니라 tutorEdit에 추가 필드가 필요합니다. 컨트롤러에 이것을 추가하고 싶지만 어떻게해야합니까? – ajt

+0

@ajt - 추가 필드 - 폼에 추가하십시오 (이름이 TutorEdit 필드의 이름인지 확인하십시오). 'put'에 관해서는 'if' 절의'OR '('||')을 사용하십시오. – AgRizzo

관련 문제