[英]yii2 gridview count(): Parameter must be an array or an object that implements Countable php 7.2
Error: 错误:
count(): Parameter must be an array or an object that implements Countable
count():参数必须是实现Countable的数组或对象
The error comes from \\vendor\\yiisoft\\yii2\\helpers\\BaseHtml.php (line 1302) 错误来自\\ vendor \\ yiisoft \\ yii2 \\ helpers \\ BaseHtml.php(第1302行)
$content = Html::tag('tr', implode('', $cells), $this->headerRowOptions);
which calls: vendor\\yiisoft\\yii2\\helpers\\BaseHtml.php (line 150) 该调用:vendor \\ yiisoft \\ yii2 \\ helpers \\ BaseHtml.php(第150行)
$html = "<$name" . static::renderTagAttributes($options) . '>'
which in turn calls: 依次调用:
if (count($attributes) > 1) { ...
(which is also in the same file) (也位于同一文件中)
The question is : what is the source of this error and how is it fixed/avoided? 问题是 :此错误的根源是什么?如何解决/避免该错误?
The answer is included and is found below... The cause of the problem was not very intuitive. 答案已包括在内,可以在下面找到...问题的原因不是很直观。
This question was added for the sole purpose of helping others who might come across a similar problem using yii2 and upgrading to php 7.2 添加此问题的唯一目的是帮助其他人使用yii2并升级到php 7.2时可能遇到类似的问题
The reason for the problem in this case was that in the gridview the property 'headerRowOptions' was set by an anonymous function: 在这种情况下出现问题的原因是,在gridview中,属性“ headerRowOptions”是由匿名函数设置的:
'headerRowOptions' => function ($model, $key, $index, $grid) {
return ['style' => 'vertical-align: middle !important;'];
},
When changed to an array, the error was gone and everything worked as expected: 当更改为数组时,错误消失了,一切都按预期工作:
'headerRowOptions' => ['style' => 'vertical-align: middle !important;'],
Hopefully this helps someone in a similar situation. 希望这可以帮助处于类似情况的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.