/** * Lists all TblPost models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => TblPost::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }
<?php use yii\widgets\ListView; use app\models\TblPost; use yii\data\ActiveDataProvider; use yii\grid\GridView; use app\config\conf; $this->title = 'My Yii Application'; ?> <center> <div class="site-index" style="width:60%;"> <?php $dataProvider = new ActiveDataProvider(['query' => TblPost::find(), 'pagination' => ['pageSize' => conf::$numberpostperpage], 'sort' => ['defaultOrder' => ['publish_date' => SORT_DESK]]]); echo ListView::widget(['dataProvider' => $dataProvider, 'itemView' => '_post']); ?> </div> </center>