cakepp$this->;用户->;在登录用户的编辑功能上保存($this->;数据)错误


cakephp $this->User->save($this->data) error on edit function of a logged user

我正试图在cakepp中为一个登录用户创建"编辑"配置文件页面。这将是添加/编辑关于用户的信息的功能。我在执行$this->User->save($this->data)函数时遇到了一个错误,我不明白问题出在哪里。

public function edit() {
   $this->User->id = $this->Auth->User('id');
    if ($this->request->is('post')) {
        if ($this->User->save($this->data)) {
            $this->Session->setFlash(__('The user has been saved'), 'flash_success');
           // $this->redirect($this->Auth->redirect());
        } else {
            var_dump($this->invalidFields());
            $this->Session->setFlash(__('The user could not be saved. Please, try again.'), 'flash_failure');
        }
    } else {
        //autocompleto il form
        $this->data = $this->User->read(null, $this->Auth->User('id'));
    }
}

观点是:

<?php 
echo $this->Form->create('User',array('action' => 'edit'));
echo $this->Form->input('name', array('label'=> 'Name'));
echo $this->Form->input('surname', array('label'=> 'Surname'));
echo $this->Form->input('id', array('type'=> 'hidden'));
echo $this->Form->end(__('Submit')); 
?>

我看到您使用了Auth组件。如果您的Auth::authorize默认值被覆盖,请确保您授予用户执行数据写入的适当权限(也许他只允许读取)。

另一个问题可能是模型中的$validate声明,强制用户输入字段值(使用'required' = true),但实际上该字段甚至不会显示在View上。如果在内部定义了'on' => 'create',则可以在数据编辑时避免此验证规则。

此外,我建议使用CakePHP debug()而不是var_dump()进行调试。