在ajax yii2上处理面包块



我在yii2中有一个breadcumbs。问题是,我使用pjax来处理数据库上表的crud。

假设,这是我的代码(在index.php视图中):

<?php
$this->title = 'Barangs';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="barang-index">
<?php
Pjax::begin([
    'timeout' => 5000,
    'id' => 'pjax-gridview'
]);
?>
<h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search', ['model' => $searchModel]);  ?>
<p>
    <?= Html::a('Create Barang', ['create'], ['class' => 'btn btn-success']) ?>
</p>

<?=
GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yiigridSerialColumn'],
        'NO_URUT',
        'CONSIGNEE',
        'CONTAINER',
        'SIZE',
        'COIL_NO',
        'NET',
        'GROSS',
        'CONTRACT_NO',
        'KET',
        'NAMA_FILE',
        'TGL_UNSTUFF',
        ['class' => 'yiigridActionColumn',
            'buttons' => [
                'view' => function($url, $model) {
                    $icon = '<span class="glyphicon glyphicon-eye-open"></span>';
                    return Html::a($icon, $url);
                },
                'update' => function($url, $model) {
                    $icon = '<span class="glyphicon glyphicon-pencil"></span>';
                    return Html::a($icon, $url);
                },
                'delete' => function($url, $model) {
                    $icon = '<span class="glyphicon glyphicon-trash"></span>';
                    return Html::a($icon, $url, [
                                "class" => 'pjaxDelete'
                    ]);
                },
                    ]
                ],
            ],
        ]);
        ?>
        <?php $this->registerJs('
            /* fungsi ini akan dijalankan ketika class pjaxDelete di klik */
            $(".pjaxDelete").on("click", function (e) {
                /* cegah link menjalankan default action */
                e.preventDefault();
                if(confirm("Are you sure you want to delete this item?")){
                    /* request actionDelete dengan method post */
                    $.post($(this).attr("href"), function(data) {
                        /* reload gridview */
                        $.pjax.reload("#pjax-gridview",{"timeout":false});
                    });
                }
            });
        ');
        ?>
        <?php Pjax::end(); ?></div>

我的问题是,没有ajax, breadcumbs将显示Home / Barangs / Create Barang。但是在ajax中,breadcumbs看起来是这样的:Home / Barangs /

我仍然需要第一个breadcumbs格式。

请建议。

当使用Pjax =>页面不刷新,但url改变使用这段代码也许你的问题解决

<?php Pjax::begin(['enablePushState' => false]); $form = ActiveForm::begin(['action' => '', 'options' => ['data-pjax' => '']]); ?>

最新更新