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
 /**
  * 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]);
     }
 }
Ejemplo n.º 6
0
 public static function getNewsFromCronAuto()
 {
     $result = 0;
     $file = Yii::getAlias('@json') . DIRECTORY_SEPARATOR . 'cron-import.json';
     if (file_exists($file)) {
         $data = file_get_contents($file);
         $data = unserialize($data);
         if ($data) {
             foreach ($data as $row) {
                 $duble = Blog::getDublicateByTitle(mb_convert_encoding($row['title'], 'UTF-8', 'Windows-1251'));
                 if (!$duble) {
                     $model = new Blog();
                     $model->title = mb_convert_encoding($row['title'], 'UTF-8', 'Windows-1251');
                     $model->image = $row['image'] ? $row['image'] : '';
                     $model->content = mb_convert_encoding($row['content'], 'UTF-8', 'Windows-1251');
                     $model->updated_at = time();
                     $model->author = (int) 1;
                     $model->save();
                     $result = 1;
                 }
                 $result = 2;
             }
         }
     }
     return $result;
 }