yii2-面对默认密码长度验证的问题



在我的注册表单模型中,我没有添加最小密码长度验证器。但是我仍然将其视为验证错误。任何人都可以帮助解决这个问题。即使我没有在规则数组中添加该验证执行,也如何停止该验证执行。以下是我的代码。

    <?php
namespace appmodels;
use appmodelsUser;
use yiibaseModel;
use Yii;
/**
 * Signup form
 */
class SignupForm extends Model {
    public $username;
    public $email;
    public $password;
    public $password_repeat;
    public $unit_id;
    public $timezone;
    /**
     * @inheritdoc
     */
    public function rules() {
        $array_rule = [
            ['username', 'filter', 'filter' => 'trim'],
            ['username', 'required'],
            ['username', 'unique', 'targetClass' => 'appmodelsUser', 'message' => 'This username has already been taken.'],
            ['username', 'string', 'min' => 2, 'max' => 255],
            ['unit_id', 'integer'],
            ['email', 'filter', 'filter' => 'trim'],
            ['email', 'required'],
            ['email', 'email'],
            ['email', 'string', 'max' => 255],
            ['email', 'unique', 'targetClass' => 'appmodelsUser', 'message' => 'This email address has already been taken.'],
           ];
return $array_rule;
    }
public function signup() {
        if (!$this->validate()) {
            print_r($this->getErrors());
        }
}
}?>

您必须为密码字段添加规则,然后可以通过$ model-> load

加载

所以添加到规则数组:

['password','safe'] or ['passwprd','string','min'=>5,'mix'=>50];

最新更新