示例#1
0
 /**
  * Finds the TblPost model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return TblPost the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = TblPost::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#2
0
<?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>