E
E
EVOSandru62015-10-28 06:24:23
Yii
EVOSandru6, 2015-10-28 06:24:23

How to display a paginator and set the number of records per page in yii1 for a grid of related data?

Good afternoon,
In the case of working with the main model, everything is clear, but here I’m not catching up a bit:

$model = Hotels::model()->fndByPk(1);

$rooms = new CActiveDataProvider('Rooms',
[
    'criteria' =>
    [
        'condition'=>
            'hotel_id = '.$model->id .
            ' AND firm_id = ' . Firms::FIRM_ID,
    ],
    'pagination' =>
    [
        'pageSize' => 20,
    ],
]);



$this->widget('GridView',
[
    'id' => 'rooms-grid',
    'dataProvider' => $rooms,
 'template'    => "{pager}\n{items}\n{pager}",

    'pager'=> array(
        'prevPageLabel' => '« назад',
        'nextPageLabel' => 'далее »',
    ),

    'columns'   =>
    [

        [
             'header' => 'Название',
             'filter' => false,
             'value' => function ($data)
             {
                 return $data->name;
             }
        ],
        [
            'class' => 'CButtonColumn',
            'template' => '{delete}',
            'deleteButtonUrl' =>
                'Yii::app()->createUrl("/sadmin/rooms/delete",["id" => $data->id])',
        ],
    ],
]);

In this case, the model 's search() method is not used , because related data, template doesn't help, pager doesn't render. And it is not clear how to regulate the number of lines per page without search .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Bukharev, 2015-10-28
@EVOSandru6

What's stopping you from doing this:

$model = Hotels::model()->fndByPk(1);
$rooms_model= new Rooms('search');
$rooms_model->hotel_id=$model->id;
$rooms_model->firm_id=Firms::FIRM_ID;
$rooms=$rooms_model->search();

$rooms can be inserted into the dataProvider of the GridView widget, since the search() method will return CActiveDataProvider

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question