Validation CakePHP:为什么不';是否显示验证错误?

Validation CakePHP:为什么不';是否显示验证错误?,validation,cakephp,Validation,Cakephp,因此,验证错误显示在“添加”操作中,但不显示在“编辑”操作中。以下是来自我的控制器的代码片段: 在这里,我得到了预期的验证错误消息: public function add() { if ($this->request->is('post')) { if ($this->User->save($this->request->data)) { $this->Session-&g

因此,验证错误显示在“添加”操作中,但不显示在“编辑”操作中。以下是来自我的控制器的代码片段:

在这里,我得到了预期的验证错误消息:

    public function add() {
        if ($this->request->is('post')) {
            if ($this->User->save($this->request->data)) {
                $this->Session->setFlash(__('The user has been saved.'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The user could not be saved. Please try again.'));
            }
        }
        $this->set('clients', $this->User->Client->find('list'));
    }
但这里没有:

    public function edit($id = null) {
        $this->User->id = $id;
        if (!$this->User->exists()) {
            throw new NotFoundException(__('Invalid user'));
        }
        if ($this->request->is('post') || $this->request->is('put')) {
            if ($this->User->save($this->request->data)) {
                $this->Session->setFlash(__('The user has been saved.'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
            }
        } else {
            $this->request->data = $this->User->read(null, $id);
            unset($this->request->data['User']['password']);
        }
        $this->set('user', $this->User->read());
        $this->set('clients', $this->User->Client->find('list'));
    }
setFlash(“无法保存用户”)消息是否正在触发

调试的输出是什么($this->User->validationErrors)-在setFlash失败消息之后添加它


您的post数组是否包含需要保存的所有字段?您的$validate中是否有post数组中没有的必填字段?(Cake将注册错误,但除非表单中有字段,否则无法显示错误)。或者另一个验证规则失败,但您没有在表单中显示该字段

如果调用正确,则在保存失败后使用read()调用将清除验证错误


那里。。我在这一行发现了它

打字错误:如果($this->User->save($this->request->data/)-extra/在结尾处,我的原始代码中有一条注释被我删除了。