php - count():参数必须是Yii2中实现Countable的数组或对象
问题描述
我在验证用户中使用 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;
}
}
这张错误页面的图片可能有助于很好地理解:
错误页面的其余部分:
我需要做什么?
解决方案
您需要升级到 Yii2 的最新版本(或至少 2.0.13) - 与 PHP 7.2 的兼容性在 2.0 13 版本中得到了显着改进,请参阅此 PR。
但一般来说,如果你使用的是最新版本的 PHP,你应该使用最新版本的 Yii - 使用最新版本的框架的过时版本可能会带来很多问题。尤其是 PHP 7.2 带来了很多 BC 中断,并且在这个版本中有很多东西被破坏了。
推荐阅读
- hive - MetaException(消息:在 Metastore Hive 3.1.1 中找不到版本信息
- javascript - 如何使用两个var制作json键值对
- java - 确保此方法调用中使用的正则表达式不会导致拒绝服务
- python - 将 24 小时值转换为 HHMMSS - 时间
- azure - 使用逻辑应用程序将多个文件夹下的文件从 sftp 传输到 sharepoint 文档库
- java - 使用 Mapping Model 将 Smooks 生成的 XML 转换为 EDI
- php - 为什么 file_put_contents 将 2 行插入 json 文件?
- python - Docker 构建映像返回错误:lambci/lambda:术语“lambci/lambda”未被识别为 cmdlet、函数、脚本文件的名称
- python - 抓取列表问题
- wordpress - 是否可以将树枝变量传递到模板中?