コード例 #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()
 {
     $model = new Ad();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
コード例 #2
0
ファイル: AdController.php プロジェクト: s-nice/snece
 /**
  * Creates a new Ad model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Ad();
     $model->create_at = time();
     $model->update_at = time();
     $model->create_uid = Yii::$app->user->identity->id;
     $model->is_show = 1;
     if ($model->load(Yii::$app->request->post())) {
         $img = UploadedFile::getInstance($model, 'img');
         if ($img) {
             $file = 'upload/' . time() . mt_rand(1, 999) . '.' . $img->extension;
             $img->saveAs($file);
             $model->img = $file;
         }
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         $adverlist = Adver::getDropList();
         return $this->render('create', ['model' => $model, 'adverlist' => $adverlist]);
     }
 }