【发布时间】:2018-08-22 10:54:44
【问题描述】:
我在验证用户时使用 xammp v3.2.2 我收到此错误:
count(): Parameter must be an array or an object that implements Countable
我不知道这个错误取决于xampp,yii2还是php v7.2.3。
in C:\xampp\htdocs\payesh\vendor\yiisoft\yii2\validators\UniqueValidator.php at line 136
if ($this->modelExists($targetClass, $conditions, $model)) {
if (count($targetAttribute) > 1) { //error mentions here
$this->addComboNotUniqueError($model, $attribute);
} else {
$this->addError($model, $attribute, $this->message);
}
}
}
这是我的用户模型:
public function signup() {
if ($this->validate()) { // the error mentions here too
$user = new User();
$user->username = $this->email;
$user->email = $this->email;
if ($user->save(false)) {
return $user;
}
}
这张错误页面的图片可能有助于理解:
错误页面的其余部分:
我该怎么办?
【问题讨论】:
-
$targetAttribute 到底是什么?错误说它需要一个数组,但 ist 不是。
-
显示您应用了唯一验证器的验证
-
@DieterKräutl 我不知道,它在 yii2 上
-
@NitinPund 你能告诉我更多吗?你是说我的示范规则吗?
-
是的,你的模型规则