Yii2 - 面临默认密码长度验证问题

时间:2016-12-16 12:36:19

标签: php yii2

在我的注册表单模型中,我没有添加Minimum Password length验证器。但我仍然把它作为验证错误。谁能帮助解决这个问题。即使我没有在rules数组中添加它,如何停止验证执行。下面是我的代码。

    <?php

namespace app\models;

use app\models\User;
use yii\base\Model;
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' => '\app\models\User', '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' => '\app\models\User', 'message' => 'This email address has already been taken.'],
           ];
return $array_rule;
    }

public function signup() {
        if (!$this->validate()) {
            print_r($this->getErrors());
        }
}
}?>

1 个答案:

答案 0 :(得分:0)

您必须为密码字段添加规则,然后才能通过$ model-&gt; load

加载

所以添加到规则数组:

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