0

profileController を使用する Vake プロジェクトの profile.ctp にプロファイルの編集ページがありますか? 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'));
}
}

しかし、SAVEをクリックしてもusers_phonesに挿入されません

4

1 に答える 1

2

save()を、複数のデータの保存をサポートするsaveAll()(またはsaveAssociated / saveMany)に置き換える必要があります。

http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-saveall-array-data-null-array-options-arrayを参照してください

于 2013-03-14T16:08:49.183 に答える