示例#1
0
 /**
  * Creates a new News model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new News();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new News model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new News();
     if ($model->load(Yii::$app->request->post())) {
         $news_images = UploadedFile::getInstance($model, 'news_img');
         $model->news_img = $news_images->name;
         $model->url = $this->utf8convert($model->title);
         $model->regist_date = date('Y/m/d');
         $model->save();
         $news_images->saveAs('images/news/' . $news_images->baseName . '.' . $news_images->extension);
         return $this->redirect(['view', 'id' => $model->news_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }