我有一个包含许多属性和验证规则的用户模型:
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'
)
),
...
);
}
这对我有意义,因为在创建用户时始终需要密码。 在某些情况下,比如编辑用户时,我不希望需要密码。没有新密码时,密码不会更改。我怎么能这样做?
答案 0 :(得分:1)
更改密码验证,如下所示: -
'password' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A password is required',
'on' => 'create'
)
),