Validation 当我们使用不同的验证集时,验证中的Cakephp 3.0问题

Validation 当我们使用不同的验证集时,验证中的Cakephp 3.0问题,validation,cakephp-3.0,Validation,Cakephp 3.0,我有一个用于更改密码功能的自定义表单。但是验证在此页面上无法正常工作 模板文件(更改密码.ctp)为: 我在controlleruserscoontroller.php中包含了changePassword()操作 public function changePassword() { $user = $this->Users->newEntity(); if (isset($this->request->data) && !

我有一个用于更改密码功能的自定义表单。但是验证在此页面上无法正常工作

模板文件(更改密码.ctp)为:

我在controlleruserscoontroller.php中包含了changePassword()操作

public function changePassword() {

        $user = $this->Users->newEntity();
        if (isset($this->request->data) && !empty($this->request->data)) {
            $user = $this->Users->patchEntity($user, $this->request->data, [
                'validate' => 'changePassword'
            ]);
            if ($user->errors()) {


                $this->Flash->success(__('Error'));
            }
        }
    }

更新您的操作,如下所示:

public function changePassword() {

        $user = $this->Users->newEntity();
        if (isset($this->request->data) && !empty($this->request->data)) {
            $user = $this->Users->patchEntity($user, $this->request->data, [
                'validate' => 'changePassword'
            ]);
            if ($user->errors()) {


                $this->Flash->success(__('Error'));
            }
        }
        $this->set(compact('user'));
    }

“工作不正常”是什么意思?描述您的问题。您能解释一下我们如何为自定义更改密码表单创建验证吗?我创建了一个用户控制器和一个名为changepassword的操作,并在UsersTable.php页面中添加了验证代码。控件将进入验证功能,但验证不适用于我。请更正上述代码,以便我可以在我的模板页面上显示验证?您的意思是要在应用程序中使用特定CRUD的集合吗?完全正确。但是我认为控件会转到验证函数,但是验证不会显示在表单的不同字段下。
public function changePassword() {

        $user = $this->Users->newEntity();
        if (isset($this->request->data) && !empty($this->request->data)) {
            $user = $this->Users->patchEntity($user, $this->request->data, [
                'validate' => 'changePassword'
            ]);
            if ($user->errors()) {


                $this->Flash->success(__('Error'));
            }
        }
    }
public function changePassword() {

        $user = $this->Users->newEntity();
        if (isset($this->request->data) && !empty($this->request->data)) {
            $user = $this->Users->patchEntity($user, $this->request->data, [
                'validate' => 'changePassword'
            ]);
            if ($user->errors()) {


                $this->Flash->success(__('Error'));
            }
        }
        $this->set(compact('user'));
    }