1

我遇到了 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模型数据未保存。

我哪里错了?

4

1 回答 1

1

如果未保存用户,请检查 else 语句中的 $this->User->validationErrors。我敢打赌,您定义了额外的验证规则,这些规则对于不在您的表单中的字段是失败的。

于 2011-11-04T14:23:50.617 回答