Two paginations on one page YII2 - php

I can’t do two paginations on one page. I have a page in the form of tabs, and each tab has a list of different products, I want to paginate each list
Here is the error code and screenshot
$posts = Wishlist::find()->where(['user_id'=>$id]);
$pagination =new Pagination([
'defaultPageSize' =>10,
'totalCount' => $posts->count()
]);
$posts = $posts->offset($pagination->offset )->limit($pagination->limit)->all();
$favs = FavLists::find()->where(['user_id'=>$id]);
$pag_favs =new Pagination([
'defaultPageSize' =>10,
'totalCount' => $favs->count()
]);
$favs = $favs->offset($pag_favs->offset )->limit($pag_favs->limit)->all();
return $this->render('view', [
'model' => $this->findModel($id),
'posts' =>$posts,
'pagination' => $pagination,
'favs' =>$favs,
'pag_favs' => $pag_favs
]);
In view 1st pagination
echo LinkPager::widget([
'pagination' => $pagination,
]);
?>
In view 2nd pagination
<?php
echo LinkPager::widget([
'pag_favs' => $pag_favs,
]);
?>

Replace pag_fvs with pagination in LinkPager. LinkPager don't have property page_fvs.
<?= LinkPager::widget([
'pagination' => $pag_favs,
]) ?>

Related

Yii2 pagination

is it possible to use post id in pagination instead of page number
example instead of :
&page=2
it will be
&id=63
Pagination code is :
function actionIndex()
{
$query = Article::find()->where(['status' => 1]);
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count()]);
$models = $query->offset($pages->offset)
->limit($pages->limit)
->all();
return $this->render('index', [
'models' => $models,
'pages' => $pages,
]);
}
view :
foreach ($models as $model) {
// display $model here
}
// display pagination
echo LinkPager::widget([
'pagination' => $pages,
]);

Two listView same page Yii2

I am trying to put two list views in the same page with Yii2 but whenever I change the page in one the second change too. Any suggestions? I searched everywhere and haven't found any similar issues although I think it's very basic. Any help?
In controller you may pass two data provider for the two list views this may help
you to solve this
public function actionView($id)
{
$model = $this->findModel($id);
$reportsToUserDataProvider = new ActiveDataProvider([
'query' => $model->parent()
]);
$reporteeDataProvider = new ActiveDataProvider([
'query' => $model->children(),
'pagination' => false,
]);
Yii::$app->session->setFlash('alert', [
'options' => ['class' => 'alert-success'],
'body' => 'Your Reportees has been updated successfully'
]);
}
return $this->render('view', [
'model' => $model,
'reportsToUserDataProvider' => $reportsToUserDataProvider,
'reporteeDataProvider' => $reporteeDataProvider,
]);
}

Site and its behaviors do not have a method or closure named "orderBy"

while i am fetching this records then getting this error how to solve it ?
public function actionIndex()
{
$query = Site::model();
$pagination = new CPagination([
'defaultPageSize' => 5,
'totalCount' => $query->count(),
]);
$countries = $query->orderBy('name')
->offset($pagination->offset)
->limit($pagination->limit)
->all();
return $this->render('view', [
'countries' => $countries,
'pagination' => $pagination,
]);
}
you should distinguish between yii1 and yii2.from your codes,you used yii1 and yii2 together.

Yii2 Error response jsono header?

Hi i have problem with pagination in linkerPage.
My problem https://gyazo.com/cc9b04c3114d6cfd09ef376b5d4374ac
I use https://github.com/kartik-v/yii2-tabs-x
when i want using pagination I gets raw html, how on the screen.
My console browser shows error
"Resource interpreted as Document but transferred with MIME type application/json:" {my url}
My controller
public function actionTestTabs()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$MovieData = seanse::find()->innerJoinWith(['idMovie', 'idRoom']
)->where(['active' => 'active'])
->groupBy('name');
$date = seanse::find()->innerJoinWith(['idMovie', 'idRoom']
)->where(['active' => 'active'])
->orderBy('name')->all();
$dataProvider = new ActiveDataProvider([
'query' => $MovieData,
'pagination' => [
'totalCount' => 1,
'pageSize' => 1,
],
]);
return $this->renderPartial('test', [
'MovieData' => $MovieData,
'dataProvider' => $dataProvider,
'date' => $date,
]);
}
My view
foreach ($month as $item) {
$items[] = [
'label' => $item,
'linkOptions' => ['data-url' => Url::to(['repertuar/test-tabs'])],
];
}
echo TabsX::widget([
'align' => TabsX::ALIGN_CENTER,
'items' => $items,
]);
what is wrong ?
Whats the problem? You've setted "json" response header in line:
Yii::$app->response->format = Response::FORMAT_JSON;
Just remove this line from code or comment it.

Yii2 - Query with Pagination

I have a Category model that has a relation with the Products model.
I am doing the following query:
$model = Category::find()->where(['slug' => $slug])->with('products')->one();
And in the view I can retrieve all the products that belong to that Category with:
foreach ($model->products as $value)...
Now I want to do the pagination in the products but I can not find how to do it in the "with" part of the query.
Try this
In Controller:
...
$pages = new Pagination(['totalCount' => $model->products->count()]);
return $this->render('index', [
'model' => $model,
'pages' => $pages,
]);
In View:
foreach ($model->products as $value) {
// display $model here
}
// display pagination
echo LinkPager::widget([
'pagination' => $pages,
]);

Categories