Ran*_*all 2 php cakephp save belongs-to
我有桌子profiles和桌子users,并且profiles有belongsTo关系users.在我profiles/edit看来,我有一个现有的下拉列表users可供选择.
然而,正如我所料,它users.id并没有被保存下来profiles.user_id.
ProfilesController.php - >编辑:
$this->set('users', $this->Profile->User->find('list'));
Run Code Online (Sandbox Code Playgroud)
并在视图 - >配置文件 - > edit.ctp
echo $this->Form->input('User');
Run Code Online (Sandbox Code Playgroud)
debug($this->request);在控制器中运行表明正确的值正被发送回控制器.保存操作如下所示:
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->Profile->save($this->request->data)) {
$this->Session->setFlash(__('The profile has been saved'));
} else {
$this->Session->setFlash(__('The profile could not be saved. Please, try again.'));
}
}
Run Code Online (Sandbox Code Playgroud)
在返回的数据中:
data => array(
'Profile' => array(
'User' => '3',
...
Run Code Online (Sandbox Code Playgroud)
这种语法错误:
echo $this->Form->input('User');
Run Code Online (Sandbox Code Playgroud)
您的模型中没有名为"User"的字段Profile.这应该是:
echo $this->Form->input('user_id');
Run Code Online (Sandbox Code Playgroud)