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
저장 교체 할 필요가
가 왜 생성이되는 참조하지? 이는 업데이트 대신 삽입하려는 경우 필요합니다. – mark
[참조하십시오.] (참조 http://stackoverflow.com/questions/15422670/cakephp-associations-error-wont-save-associated-table) –
그는 더 낫지 않습니다;) 작동 여부 (실제로 지금까지 모델을 사용하지 않았다면) 데이터를 삽입하려면 create()를 사용해야합니다. – mark