开门_查水表
- 开门_查水表 回复了 johnny1991 的回答
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方法重写了
- 开门_查水表 回复了 johnny1991 的回答
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 () { //查找账号是否存在,的函数 }]
可惜好像只能判断真假,不能当函数用
- 开门_查水表 回复了 johnny1991 的回答
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 () { //查找账号是否存在,的函数 }】``` 我是想这样来的
- 开门_查水表 回复了 johnny1991 的回答
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',】
- 开门_查水表 2018-11-06 已签到连续签到2天,获得了10个金钱
- 开门_查水表 回答了问题 我把文件放哪里去了,一脸懵逼
mv redis-5.0.0.tar.gz /root/tools 都是要加绝对路径 挺烦人的,
- 开门_查水表 2018-11-05 已签到连续签到1天,获得了5个金钱