Answer the question
In order to leave comments, you need to log in
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])',
],
],
]);
Answer the question
In order to leave comments, you need to log in
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();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question