Пример #1
0
 /**
  * Updates an existing Ad model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     if (!$this->is_access('ads/update')) {
         Yii::$app->session->setFlash('error', $this->errorInfo);
         return $this->redirect($this->redirectUrl);
     }
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         // 类型为 0:图片;1:Flash时
         if ($model->media_type == 0 || $model->media_type == 1) {
             /* 处理上传的图片 */
             if ($_FILES['Ad']['error']['ad_file'] === 0) {
                 /* 把文件的路劲赋值给image字段 */
                 $model->ad_code = File::uploadImage($model, 'ad_file', 'other');
             }
         }
         if ($model->save()) {
             Yii::$app->session->setFlash('success', '编辑成功');
         }
         return $this->redirect(['index']);
     } else {
         $AdPosition = new AdPosition();
         Yii::$app->view->params['meta_title'] = '编辑广告';
         $mediaList = $model->media_type_list();
         $position = $AdPosition->ad_position();
         return $this->render('update', ['model' => $model, 'mediaList' => $mediaList, 'position' => $position]);
     }
 }
Пример #2
0
 /**
  * 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.');
     }
 }
Пример #3
0
        <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);
    }