有两个例子:刷新时间和数据显示排序
1、刷新时间
(1)控制器中的方法:Time
- public function actionTime()
- {
- return $this->render(‘time’,[‘time’=>date(“h:i:s”)]);
- }
(2)视图中的显示:Time.php
- <?php
- use yii\widgets\Pjax;
- use yii\helpers\Html;
- ?>
- <? Pjax::begin()?>
- <?=Html::a(‘time’,[‘hello/time’],[‘class’=>’btn btn-lg btn-primary’])?>
- <h3>Current Time:<?=$time?></h3>
- <? Pjax::end()?>
运行界面如下:点击按钮即可刷新
(2)数据显示的排序:
只需要在GridView显示的地方加上Pjax即可:
- <?Pjax::begin();?>
- <?echo GridView::widget([
- ‘dataProvider’ => $dataProvider,
- ‘filterModel’ => $searchModel,
- ‘columns’ => [
- [‘class’ => ‘yii\grid\CheckboxColumn’],
- ‘id’,
- ‘name’,
- ‘password’,
- [‘class’ => ‘yii\grid\ActionColumn’,
- ],
- ],
- ]); ?>
- <?Pjax::end();?>
运行结果如下:通过点击ID、Name、Password可以进行排序
正文完