2013-03-14 4 views
0

profileController를 사용하는 Vake 프로젝트 profile.ctp에 프로필 편집 페이지가 있습니까? 나는 URL에 대한 입력 필드를 추가하려면, 휴대폰 등하지만 사용자가 나는 형태CakePhp에서 한 사용자에게 더 많은 데이터 추가

<? 
echo $this->Form->create(); 
echo $this->Form->input('UsersPhones.phone'); 
echo $this->Form->end('Save'); 
?>    

을 만들어 내보기에

USERS_PHONES 
id 
user_id 
phone 

다른 테이블이라고 users_phones을 만들 수 있도록 더 전화를 할 수 있습니다 모델 I 이 :

public $hasMany = array(
    'Phones' => array(
     'className'  => 'UsersPhones', 
     'foreignKey' => 'user_id', 
     'dependent'  => true 
    ) 
); 

컨트롤러 :

$this->User->id = $this->Auth->user('id'); 
if ($this->request->is('post')) { 
    if ($this->User->save($this->request->data, array('validate' => false))) { 
    $this->Session->setFlash('Profile updated succsessefully!', 
             'default', array('class' => 'okmsg')); 

    $this->redirect($this->request->here); 
    } else { 
$this->Session->setFlash('Profile could not be saved. Please, try again.', 
                'default', array('class' => 'errormsg')); 
} 
} 
,

하지만 난 그것을 저장을 클릭 할 때 늘 여러 데이터를 저장하는 지원 시려면() (또는 saveAssociated/saveMany)와 users_phones

저장 교체 할 필요가
+0

가 왜 생성이되는 참조하지? 이는 업데이트 대신 삽입하려는 경우 필요합니다. – mark

+0

[참조하십시오.] (참조 http://stackoverflow.com/questions/15422670/cakephp-associations-error-wont-save-associated-table) –

+0

그는 더 낫지 않습니다;) 작동 여부 (실제로 지금까지 모델을 사용하지 않았다면) 데이터를 삽입하려면 create()를 사용해야합니다. – mark

답변

2

()에 삽입합니다.

당신의 저장() 또는 시려면() 전에 호출) (http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-saveall-array-data-null-array-options-array

+0

저장되지 않습니다! 명명 규칙을 다시 확인 하시겠습니까? 괜찮습니까? 데이터베이스 : user_phones $ hasMany = array ('UserPhones'); 및 UserController 입력 $ this-> Forms-> input ('UserPhones.phone') 어딘가에서 실수를 했습니까? –

+0

저장하지 않으면'$ this-> User-> validationErrors'를 체크하십시오 - 에러를 포함해야합니다. – mark

+0

메시지를 성공적으로 보내지 만 저장하지 않는 오류는 없습니다. [참조하십시오] (http://stackoverflow.com/questions/15422670/cakephp-associations-error-wont-save-associated-table) –

관련 문제