简体   繁体   English

yii2 gridview count():参数必须是实现Countable php 7.2的数组或对象

[英]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.

相关问题 count():参数必须是在Yii2中实现Countable的数组或对象 - count(): Parameter must be an array or an object that implements Countable in Yii2 PHP 7.2: count(): 参数必须是数组或实现Countable的object - PHP 7.2: count(): Parameter must be an array or an object that implements Countable PHP 7.2 警告count():参数必须是数组或实现Countable的object - PHP 7.2 Warning count(): Parameter must be an array or an object that implements Countable 如何修复 PHP 7.2 警告:count():参数必须是一个数组或实现 Countable in errors.php 的数组或 object? - How to fix PHP 7.2 Warning: count(): Parameter must be an array or an object that implements Countable in errors.php? 错误 php 7.1 -&gt; 7.2:count(): Parameter must be an array or an object that implement Countable in concrete5 addon - Error php 7.1 -> 7.2 :count(): Parameter must be an array or an object that implements Countable in concrete5 addon PHP警告:count():参数必须是数组或实现Countable的对象? - PHP Warning: count(): Parameter must be an array or an object that implements Countable? count():参数必须是一个数组或一个 object 实现 php 中的可计数错误 - count(): Parameter must be an array or an object that implements Countable error in php PHP count():参数必须是一个数组或一个实现了Countable的对象 - PHP count(): Parameter must be an array or an object that implements Countable PHP:count():参数必须是数组或者实现了Countable的对象 - PHP: count(): Parameter must be an array or an object that implements Countable PHP 出现问题“消息:count():参数必须是数组或实现可计数的 object” - Problem with PHP “Message: count(): Parameter must be an array or an object that implements Countable ”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM