Ejemplo n.º 1
0
 /**
  * Creates a new Blog model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Blog();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 2
0
 /**
  * Creates a new Blog model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Blog();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->getSession()->setFlash('alert', ['body' => 'บันทึกข้อมูล Blog เรียบร้อยแล้ว', 'options' => ['class' => 'alert-success']]);
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 3
0
 /**
  * Creates a new Blog model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Blog();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         Yii::$app->session->setFlash('info', Json::encode($model->errors));
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 4
0
 public function actionAddBlog()
 {
     $model = new Blog();
     $image = new Image();
     $data = Yii::$app->request->post();
     $model->load($data, '');
     $image->img = UploadedFile::getInstancesByName("image");
     if ($image->validate() && $model->save()) {
         if (!empty($model->categorys)) {
             $model->setCategories();
         }
         if (!empty($image->img)) {
             $image->uploads($model, Image::BLOG_STATUS);
         }
         return $model;
     }
     return array_merge($model->getErrors(), $image->getErrors());
 }
Ejemplo n.º 5
0
 public function actionCreate()
 {
     $this->layout = '/adminka';
     $model = new Blog();
     $time = time();
     if ($model->load(Yii::$app->request->post())) {
         if (UploadedFile::getInstance($model, 'file')) {
             $uploaddir = Yii::getAlias('@frontend') . '/web/upload/upload_news/';
             FileHelper::createDirectory($uploaddir);
             $file = \yii\web\UploadedFile::getInstance($model, 'file');
             $file->saveAs($uploaddir . $time . '.' . $file->extension);
             $model->image = $time . '.' . $file->extension;
         }
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 6
0
 /**
  * Creates a new Blog model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Blog();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if ($model->status == Blog::STATUS_PUBLISHED) {
             return $this->redirect($model->viewUrl);
         }
         return $this->redirect(['manage']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }