0
votes

I need to display number of grouped database records in Yii2 using GridView widget and ActiveDataProvider. I'm trying to do that in this way:

$dpar = records::find()->select(['COUNT(*) as counts'])->
groupBy(['DATE(datetime)']);

$dataPpar = new ActiveDataProvider(['query' => $dpar]);

Query works fine, but then i can't display my data in GridView

<?= GridView::widget([
'dataProvider' => $dataPpar,
'columns' => [
    'counts',
],
]);?>

All i receive is a correct (!!) number of rows with "not set" in every cell. Is there a way to solve it?

1
did you define counts as a parameter in your model? public $counts. it seems your query is correct. can you put your data in response and databasemehri abbasi
I didn't define it - it's just a simple report page i need to do, so i thought that ActiveDataProvider will be enough. But IT HELPED! THANK YOU!Evgenii Pradedov

1 Answers

0
votes

Thanks! All i had to do was addingpublic $counts to my model!