gpt4 book ai didi

validation - CakePHP:为什么不显示验证错误?

转载 作者:行者123 更新时间:2023-12-04 05:50:05 28 4
gpt4 key购买 nike

因此,验证错误会出现在我的添加操作中,但不会出现在我的编辑操作中。以下是我的 Controller 的片段:

在这里,我按预期收到验证错误消息:

    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'));
}

最佳答案

如果我没记错的话,在保存失败后使用 read() 调用将清除验证错误。

在那里..我找到了 http://book.cakephp.org/1.3/view/1017/Retrieving-Your-Data#read-1029

关于validation - CakePHP:为什么不显示验证错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10174474/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com