/** * Finds the Lookup model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Lookup the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Lookup::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/* @var $searchModel app\models\SearchPost */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = '文章'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="post-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('创建文章', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'title', 'content:ntext', 'tags:ntext', ['attribute' => 'status', 'value' => function ($model) { $lookup = new Lookup(); $lookupModel = $lookup->findOne($model->status); return $lookupModel->name; }], ['attribute' => 'create_time', 'format' => ['date', 'php:Y-m-d']], 'author_id', ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>