Beispiel #1
0
 /**
  * Creates a new Ad model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (!$this->is_access('ads/create')) {
         Yii::$app->session->setFlash('error', $this->errorInfo);
         return $this->redirect($this->redirectUrl);
     }
     $model = new Ad();
     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('create', ['model' => $model, 'mediaList' => $mediaList, 'position' => $position]);
     }
 }