2009-11-29 3 views
1

다른 개체와 몇 가지 외래 키 관계가있는 cakephp 개체 (SecurityPerson)가 있습니다. 모델에서 이러한 개체에 대한 참조 것 여기외래 키 참조를 제외하고 CakePHP 추가/수정 양식이 작동 중임

echo $form->input('ContractNumber'); 
echo $form->input('Location'); 

:

var $belongsTo = array(
    'ContractNumber' => array(
     'className' => 'ContractNumber', 
     'foreignKey' => 'contract_number_id', 
     'conditions' => '', 
     'fields' => '', 
     'order' => '' 
    ), 
    'Location' => array(
     'className' => 'Location', 
     'foreignKey' => 'location_id', 
     'conditions' => '', 
     'fields' => '', 
     'order' => '' 
    ) 
); 

그리고 여기가와 관계있는의 여기

는 foriegn 키 참조의 풀다운 메뉴를 생성하는 것 추가/편집 뷰 코드입니다 add() 컨트롤러의 일부 :

if (!empty($this->data)) { 
     $this->SecurityPerson->create(); 
     if ($this->SecurityPerson->save($this->data)) { 
      $this->Session->setFlash(__('The SecurityPerson has been saved', true)); 
      $this->redirect(array('action'=>'index')); 
     } else { 
      $this->Session->setFlash(__('The SecurityPerson could not be saved. Please, try again.', true)); 
     } 
    } 
    $contractNumbers = $this->SecurityPerson->ContractNumber->find('list'); 
    $locations = $this->SecurityPerson->Location->find('list'); 
    $this->set(compact('contractNumbers', 'locations')); 

모두 나에게 좋아 보인다. includi 추가 및 편집 페이지에서 풀다운에 대해 생성 된 HTML을 생성하십시오. 하지만 ... sercurity_person 행에 null 만 추가됩니다.

누구든지 쉽게 무슨 일이 벌어지고 있는지 또는 문제 해결에 좋은 시작을 줄 수 있습니까?

편집 : 지금까지 시도했다 : 나는 SQL 쿼리보고 해봤

. 외부 키 ID의 필드 이름은 INSERT 또는 UPDATE 문에 표시되지 않습니다.

나는 $data 구조를 살펴 보았습니다. 외래 키 참조는 다음과 같이 : => 1

답변

0

확인 [ContractNumber] => 2 [위치], 폼 입력은 다음과 같이 수행해야 밝혀 :

echo $form->input('contract_number_id', array('type' => 'select')); 
    echo $form->input('location_id', array('type' => 'select'));