开门_查水表

开门_查水表

这家伙有点懒,还没写个性签名!

  • 财富值115
  • 威望值0
  • 总积分175

个人信息

  • 回复了 的回答

    yii\validators\Validate的源码,应该是可以的

    public function validateAttributes($model, $attributes = null)
        {
            if (is_array($attributes)) {
                $newAttributes = [];
                $attributeNames = $this->getAttributeNames();
                foreach ($attributes as $attribute) {
                    if (in_array($attribute, $attributeNames, true)) {
                        $newAttributes[] = $attribute;
                    }
                }
                $attributes = $newAttributes;
            } else {
                $attributes = $this->getAttributeNames();
            }
    
            foreach ($attributes as $attribute) {
                $skip = $this->skipOnError && $model->hasErrors($attribute)
                    || $this->skipOnEmpty && $this->isEmpty($model->$attribute);
                if (!$skip) {
                    if ($this->when === null || call_user_func($this->when, $model, $attribute)) {
                        $this->validateAttribute($model, $attribute);
                    }
                }
            }
        }
    

    已经解决了。继承父类把父类的find方法,getdb方法重写了

  • 回复了 的回答

    yii\validators\Validate的源码,应该是可以的

    public function validateAttributes($model, $attributes = null)
        {
            if (is_array($attributes)) {
                $newAttributes = [];
                $attributeNames = $this->getAttributeNames();
                foreach ($attributes as $attribute) {
                    if (in_array($attribute, $attributeNames, true)) {
                        $newAttributes[] = $attribute;
                    }
                }
                $attributes = $newAttributes;
            } else {
                $attributes = $this->getAttributeNames();
            }
    
            foreach ($attributes as $attribute) {
                $skip = $this->skipOnError && $model->hasErrors($attribute)
                    || $this->skipOnEmpty && $this->isEmpty($model->$attribute);
                if (!$skip) {
                    if ($this->when === null || call_user_func($this->when, $model, $attribute)) {
                        $this->validateAttribute($model, $attribute);
                    }
                }
            }
        }
    

    ['name','unique','targetAttribute' => 'name', 'message' => '账号已存在'],
    直接这样写的话,好像不能灵活查询其他库的账号吧,
    所以想用

    ['name', 'unique', 'when' => function () {
            //查找账号是否存在,的函数
        }]
    

    可惜好像只能判断真假,不能当函数用

  • 回复了 的回答

    yii\validators\Validate的源码,应该是可以的

    public function validateAttributes($model, $attributes = null)
        {
            if (is_array($attributes)) {
                $newAttributes = [];
                $attributeNames = $this->getAttributeNames();
                foreach ($attributes as $attribute) {
                    if (in_array($attribute, $attributeNames, true)) {
                        $newAttributes[] = $attribute;
                    }
                }
                $attributes = $newAttributes;
            } else {
                $attributes = $this->getAttributeNames();
            }
    
            foreach ($attributes as $attribute) {
                $skip = $this->skipOnError && $model->hasErrors($attribute)
                    || $this->skipOnEmpty && $this->isEmpty($model->$attribute);
                if (!$skip) {
                    if ($this->when === null || call_user_func($this->when, $model, $attribute)) {
                        $this->validateAttribute($model, $attribute);
                    }
                }
            }
        }
    
    'name', 'unique', 'when' => function () {
            //查找账号是否存在,的函数
        }】```
    
    我是想这样来的
    
  • 回复了 的回答

    yii\validators\Validate的源码,应该是可以的

    public function validateAttributes($model, $attributes = null)
        {
            if (is_array($attributes)) {
                $newAttributes = [];
                $attributeNames = $this->getAttributeNames();
                foreach ($attributes as $attribute) {
                    if (in_array($attribute, $attributeNames, true)) {
                        $newAttributes[] = $attribute;
                    }
                }
                $attributes = $newAttributes;
            } else {
                $attributes = $this->getAttributeNames();
            }
    
            foreach ($attributes as $attribute) {
                $skip = $this->skipOnError && $model->hasErrors($attribute)
                    || $this->skipOnEmpty && $this->isEmpty($model->$attribute);
                if (!$skip) {
                    if ($this->when === null || call_user_func($this->when, $model, $attribute)) {
                        $this->validateAttribute($model, $attribute);
                    }
                }
            }
        }
    
    'state', 'required', 'when' => function ($model) {
            return $model->country == 'USA';
        }】
    
    
    不是
    
    【'state', 'validateAttributes',】
    
  • if ($this->when === null || call_user_func($this->when, $model, $attribute)) {
        $this->validateAttribute($model, $attribute);
    }
    

    看样子是只能判断真假了

    郁闷了了了

  • 提出了问题
    挺着急的,在线等
  • 2018-11-06 已签到
    连续签到2天,获得了10个金钱
  • mv redis-5.0.0.tar.gz /root/tools 都是要加绝对路径 挺烦人的,

  • 2018-11-05 已签到
    连续签到1天,获得了5个金钱
助理 等级规则
175/200
资料完整度
10/100
用户活跃度
10/100

Ta的关注

1

Ta的粉丝

0

Ta的访客

5