在Pjax容器(Yii2)内的特定URL上设置enablePushState = false

时间:2016-11-13 13:35:28

标签: yii2 pjax

我需要pjax来处理更改状态点击并且它工作正常但不希望它也更改URL。以下是代码:

<?php Pjax::begin(['id'=>'pjax-container-agency-index', 'timeout' => 10000, 'enablePushState' => true]); ?>
<?= GridView::widget([...,
             [
                'label' => 'Status',
                'format' => 'raw',
                'value' => function ($data) {
                    if ($data->deactive == 0) {
                        return Html::a(FA::i('circle'), ['agency/change-status', 'id' => $data->member_id, 'set' => 1], ['onclick' => "return confirm('Deactive this state/site?');", 'class' => 'status-inactive']);
                    } else {
                        return Html::a(FA::i('circle'), ['agency/change-status', 'id' => $data->member_id, 'set' => 0], ['onclick' => "return confirm('Active this state/site?');", 'class' => 'status-active']);
                    }
                },
             ],
]);
<?php Pjax::end(); ?>

actionChangeStatus()如下:

public function actionChangeStatus($id, $set) {
    if (!empty($id) && isset($set)) {
        $localGovt = $this->findModel($id);
        $localGovt->deactive = $set;
        if ($localGovt->save()) {
            Yii::$app->getSession()->setFlash('success-status', 'State Status Changed');
        } else {
            Yii::$app->getSession()->setFlash('error-status', 'There is some error. Please consult with Admin.');
        }
        $searchModel = new AgencySearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

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

注意:我需要'enablePushState' => true其他活动,因此我无法将其更改为false内的Pjax::begin

2 个答案:

答案 0 :(得分:0)

我相信它是

'enableReplaceState' => true

答案 1 :(得分:0)

将此属性传递给Pjax: Pjax::begin(['enablePushState' => false]); 这对我有用。