Exemple #1
0
 /**
  * Creates a new Post model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Post();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         // Привязка загруженных файлов к id статьи
         $post_id = $model->id;
         Images::updateAll(['post_id' => $post_id, 'r_id' => null], ['r_id' => Yii::$app->request->cookies->getValue('r_id')]);
         Files::updateAll(['post_id' => $post_id, 'r_id' => null], ['r_id' => Yii::$app->request->cookies->getValue('r_id')]);
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         $model->loadDefaultValues();
         if ($model->isNewRecord) {
             $model->date = (new \DateTime('now', new \DateTimeZone('Europe/Moscow')))->format('Y-m-d H:i:s');
             $model->author_id = Yii::$app->user->getId();
         }
         return $this->render('create', ['model' => $model]);
     }
 }
Exemple #2
0
 public function actionGenerateMonth($year, $month)
 {
     $this->month = $month;
     $this->year = $year;
     for ($i = 0; $i <= 12; $i++) {
         $this->znak = $i;
         $model = new Post();
         if ($i == 0) {
             $url = $this->_url_all;
             $this->alt = $this->_alt_all;
             $title = $this->_title_all;
             $meta_title = $this->_meta_title_all;
             $meta_descr = $this->_meta_descr_all;
             $short = $this->_short_all;
             $full = $this->_full_all;
         } else {
             $url = $this->_url;
             $this->alt = $this->_alt;
             $title = $this->_title;
             $meta_title = $this->_meta_title;
             $meta_descr = $this->_meta_descr;
             $short = $this->_short;
             $full = $this->_full;
         }
         $model->author_id = 1;
         $model->category_id = 66;
         $model->date = date('Y-m-d H:i:s');
         $model->url = $this->replace($url);
         $model->title = $this->replace($title);
         $model->meta_title = $this->replace($meta_title);
         $model->meta_descr = $this->replace($meta_descr);
         $model->short = $this->replace($short);
         $model->full = $this->replace($full);
         $model->approve = 0;
         //        var_dump($model->short); die;
         //echo GlobalHelper::rusMonth($month).' '.($i > 0) ? GlobalHelper::rusZodiac($i) : 'Все знаки'.' ';
         if ($model->save()) {
             echo 'OK';
         } else {
             var_dump($model->getErrors());
         }
         echo PHP_EOL;
     }
 }