문제

I have a User model with a lot of attributes and validation rules:

class User extends AppModel {
    public $hasMany = 'Serviceorder';

    public $validate = array(
        'name' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'A name is required'
            )
        ),
        ...
        'password' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'A password is required'
            )
        ),
        ...
    );
}

This makes sense to me because when creating a user a password is always required. In some cases, like when editing a user, I don't want the password to be required. When there's no new password, the password is not changed. How can I do that?

도움이 되었습니까?

해결책

change the password validation as below :-

   'password' => array(
        'required' => array(
            'rule' => array('notEmpty'),
            'message' => 'A password is required',
            'on' => 'create'
        )
    ),
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top