kartik-v / yii2-grid

Enhanced GridView with various utilities for Yii Framework 2.0
http://demos.krajee.com/grid
Other
557 stars 302 forks source link

PHP8: src/GridView.php -> Line 1311 -> Cannot access offset of type string on string #972

Closed ExpandXSoln closed 3 years ago

ExpandXSoln commented 3 years ago

I have converted my project to PHP8, and other than what mentioned in the subject of the issue, everything else seems to be working fine for now with this plugin, can you please let me know what should be changed on this line to make it compatible to PHP8?

THanks Aditya

ExpandXSoln commented 3 years ago

Any comments on this issue?

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ExpandXSoln commented 3 years ago

@kartik-v Any suggestions on how to resolve this issue? Would be really helpful as this is last piece of conversion is remaining.

kartik-v commented 3 years ago

What is the value of your primary key - is it a string or an object?

ExpandXSoln commented 3 years ago

Hi, I use grid view in following way

GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel'=> $searchModel, ....

]);

Where $dataProvider is populated through the Search model and it returns Object array. I am not sure if that answers your question but hope helps. Also this grid view has editable columns as well.

Issue is coming when I add 'rowOptions', sample code for rowOptions is as given below

'rowOptions' => function($model){ $returnContent =['style'=>'background-color:#12322,color:white','title'=>'Below reorder level']; return $returnContent; },

ExpandXSoln commented 3 years ago

@kartik-v found the issue, all thanks to you to pointing in the direction to check, actually I have defined $returnStatus=''; and there were bunch of conditions that were populating array to it as given in above comment. When it does not go into any of those conditions, it was trying to return string from row option due to this. I changed the declaration to $returnStatus=[]; and it worked. Unfortunately same code is working in lower versions of PHP without any issue so was assuming it is something related to the PHP8.

Thank you for your prompt reply and direction given. Closing this issue as it is not an issue at all in your plugin :-)