我遇到了 CakePHP 2.0.2 的问题。我想创建一个“编辑配置文件”操作。这是我的控制器操作:
public function edit_profile() {
if ($this->request->is('get')) {
$this->request->data = $this->User->findById($this->Auth->user('id'));
} else {
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('Your profile has been updated'));
}
}
}
这是我的观点:
<h2>Edit Profile</h2>
<?php
echo $this->Form->create('User');
echo $this->Form->input('id', array('type' => 'hidden'));
echo $this->Form->input('first_name');
echo $this->Form->input('last_name');
echo $this->Form->input('email');
echo $this->Form->end('Save Profile');
?>
但是,当我提交表单时,似乎什么也没发生。我没有收到成功消息,也没有收到错误消息。如果我将 else 语句添加到补码if ($this->User->save($this->request->data))
,则执行该代码块,表明User
模型数据未保存。
我哪里错了?