/** * Finds the AdPosition model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return AdPosition the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = AdPosition::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<p class="action"> <?php echo Html::a('添加广告', ['create'], ['class' => 'btn btn-success']); ?> </p> </div> <?php Pjax::begin(); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => ['ad_name', ['header' => Html::a('广告位置', 'javascript:void(0);'), 'content' => function ($model) { if ($model->position_id < 1) { return '站外广告'; } return AdPosition::findOne($model->position_id)->position_name; }], ['header' => Html::a('媒介类型', 'javascript:void(0);'), 'content' => function ($model) { switch ($model->media_type) { case 0: return '图片'; case 1: return 'Flash'; case 2: return '代码'; case 3: return '文字'; } }], ['attribute' => 'start_time', 'value' => function ($model) { if ($model->start_time > 0) { return date('Y-m-d', $model->start_time); }