yii2 listview分页,错误的网址

时间:2015-07-29 14:33:23

标签: php jquery pagination yii2 pjax

我正在创建一个显示议程项目的小部件

小部件模型:

JPA

搜索模型:

<?php
namespace infoweb\agenda\widgets;

use Yii;
use yii\bootstrap\Widget;

class Agenda extends Widget
{
public $template = '_agenda';
public $pageSize = 4;

public function init()
{
    parent::init();
}

/**
 * @return null|string
 */
public function run()
{
    $searchModel = new Search([
        'pageSize' => $this->pageSize,
    ]);
    $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

    return $this->render('agenda', ['dataProvider' => $dataProvider, 'template' => $this->template]);
}
}

小工具视图:

<?php

namespace infoweb\agenda\widgets;

use Yii;
use yii\data\ActiveDataProvider;

use infoweb\agenda\models\Agenda as AgendaModel;

class Search extends AgendaModel
{
public $pageSize;

/**
 * Creates data provider instance with search query applied
 * @return ActiveDataProvider
 */
public function search($params)
{
    $query = AgendaModel::find()->joinWith('translations')->where(['active' => 1]);

    $query->andFilterWhere(['language' => Yii::$app->language]);

    $dataProvider = new ActiveDataProvider([
        'query' => $query,
        'sort' => ['defaultOrder' => ['date' => SORT_DESC]],
        'pagination' => [
            'pageSize' => $this->pageSize,
        ],
    ]);

    if (!($this->load($params) && $this->validate())) {
        return $dataProvider;
    }

    return $dataProvider;
}
}

Listview视图:

<?php
use yii\widgets\Pjax;
?>

<?php

Pjax::begin();

echo \yii\widgets\ListView::widget([
    'dataProvider' => $dataProvider,
    'itemView' => $template,
    'summary' => false,
    'itemOptions' => [
        'class' => 'agenda',
    ],
]);

Pjax::end();

问题1(最重要):
当我点击寻呼机时,网址为<?php use yii\helpers\Html; ?> <div class="date"> <div class="day"><?= date('d', $model->date) ?></div> <hr> <div class="month"><?= date('m', $model->date) ?></div> </div> <div class="content"> <h3><?= $model->name ?></h3> <p><?= $model->short_description ?></p> <div class="pull-left"><strong>Plaats</strong>: Lorem ipsum</div> <div class="pull-left hidden-xs">&nbsp;&bull;&nbsp;</div> <div class="pull-left"><strong>Aanvangsuur</strong>: <?= date('H:i', strtotime($model->time)) ?> uur</div> </div> <div class="image hidden-xs hidden-sm"> <?= Html::img($model->getImage()->getUrl('200x'), ['class' => 'img-responsive']) ?> </div> <div class="clearfix"></div> ,但应该没有site/index?page=2&per-page=4

问题2: 我正在使用jQuery插件matchHeight,当我转到另一个页面时,该插件不再起作用了。 我应该再次初始化吗?怎么样?

修改

site/index

问题3:如果我更改$(document).on('pjax:complete', this.initMatchHeight);,则无效。 我需要每页项目的默认值,但是在网址中更改它也会很好

修改

使用&per-page=4,而不是'defaultPageSize' => $this->pageSize,

1 个答案:

答案 0 :(得分:1)

结果证明这很容易:

'pagination' => [
    'pageSize' => $this->pageSize,
    'route' => '',
],