我在 Vake 项目 profile.ctp 中有一个使用 profileController 的编辑配置文件页面?我想为 url、电话等添加输入字段,但用户可以拥有更多电话,所以我创建了另一个名为 users_phones 的表
USERS_PHONES
id
user_id
phone
在我看来,我创建了表格
<?
echo $this->Form->create();
echo $this->Form->input('UsersPhones.phone');
echo $this->Form->end('Save');
?>
在模型中我有:
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'));
}
}
但是当我点击保存它不会插入到 users_phones