2016-02-26 71 views
0

我有這樣的代碼在佈局/ main.php文件:如何更新頁面的其他部分(使用PJAX)?

<div class="wrap"> 
<? \yii\widgets\Pjax::begin(['id' => 'nav_pjax'])?> 
<?php 
NavBar::begin([ 
    'brandLabel' => 'Название компании', 
    'brandUrl' => Yii::$app->homeUrl, 
    'options' => [ 
     'id' => 'ww', 
     'class' => 'navbar-inverse navbar-relative', 
    ], 
]); 

echo Nav::widget([ 
    'options' => ['class' => 'navbar-nav navbar-right', 'id' => 'ww'], 
    'items' => User::getMenuItemsByRoleUser(!Yii::$app->user->isGuest ? Yii::$app->user : false,Yii::$app->user->isGuest) 
]); 
NavBar::end(); 
?> 
<? \yii\widgets\Pjax::end()?> 
<div class="container" id="content_inner"> 
    <? \yii\widgets\Pjax::begin(['timeout' => '3000'])?> 
    <?= Breadcrumbs::widget([ 
     'homeLink'=>[ 
      'label' => 'Главная', // required 
      'url' => \yii\helpers\Url::home(),  // optional, will be processed by Url::to() 
     ], 
     'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [], 
    ]) ?> 

    <?= $content ?> 
    <? \yii\widgets\Pjax::end()?> 
</div> 

當我點擊進入導航欄鏈接,服務器返回的內容,我想投入DIV CLASS =「容器」 ID = 「content_inner」。我該怎麼做?或者我應該完全刷新頁面?

回答

1

你並不需要兩個pjax小部件,你可以簡單地嘗試:

1)只更新內容

<div class="wrap"> 

     <?php /* navbar */ ?> 

     <div class="container" id="content_inner"> 
      <?php \yii\widgets\Pjax::begin([ 
       'id' => 'nav_pjax', 
       'timeout' => '3000', 
       'linkSelector' => '.navbar-nav a', // use pjax on navbar links 
      ]); ?> 

       <?php /* breadcrumb and content */ ?> 

      <?php \yii\widgets\Pjax::end(); ?> 
     </div> 

</div> 

瞭解更多關於linkSelector

2)更新導航欄和內容

<div class="wrap"> 
    <?php \yii\widgets\Pjax::begin([ 
     'id' => 'nav_pjax', 
     'timeout' => '3000', 
    ]); ?> 

      <?php /* navbar */ ?> 

      <div class="container" id="content_inner"> 
       <?php /* breadcrumb and content */ ?> 
      </div> 

    <?php \yii\widgets\Pjax::end(); ?> 
</div>