1

I have a query like so

    ::find()->where(['cdID' => $id])->orderBY(['id'=>SORT_DESC])->limit(5);

I am getting all the records not just the last 5. When I capture the variable in Netbeans I see that everything looks like is it setup properly

$query          
params  array[0]        
*yii\base\Component*_events array[0]        
*yii\base\Component*_behaviors  array[0]        
where   array[1]        
    [cdID]  string  "1" 
limit   integer 5   
orderBy array[1]        
    [id]    integer 3   

but when it gets to the GridView it doesn't show properly. Here is my gridview

<?= GridView::widget([
        'dataProvider' => $dataProvider,
        'layout'=>"{items}",
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            [
                'attribute'=>'dDate',
                'value'=>function($data){
                    $nDate = date_create($data->dDate);
                    return date_format($nDate,"M d, Y h:iA");
                },
            ],
            [
                'attribute'=>'transType',
                'value'=>function($data){
                    return $data->transTypeDescripts->sCode;
                },
                'contentOptions' => ['class' => 'text-center'],
            ],
            [
                'attribute'=>'ammount',
                'value'=>function($data){
                    return money_format('$%(#10.2n', $data->amount);
                },
                'contentOptions' => ['class' => 'text-right'],
            ],
            [
                'class' => 'yii\grid\ActionColumn',
                'visibleButtons'=>[
                    'delete'=>false,
                    'update'=>false,
                ],
            ],
        ],
    ]); ?>

Any thoughts on what might be going on, I really don't want to step trough the whole code base if I don't have to.

2 Answers2

1

I had to set

'pagination' => false,

in my $dataProvider to get only the 5 with the query that was setup. Found the answer here

LIMIT is not working in ActiveDataProvider

Community
  • 1
  • 1
0

you have to mention in pagination.. Page size that will define how many records u need to display..

            'pagination' => [
                'pageSize' => 10
            ],