Example #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()) {
         return $this->redirect(['/home/post']);
     }
     return $this->render('create', ['model' => $model]);
 }
Example #2
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()) {
         Yii::$app->userData->updateKey('post_count', Yii::$app->user->id);
         //插入记录(Feed)
         $title = Html::a(Html::encode($model->title), $model->url);
         preg_match_all("/<[img|IMG].*?src=\"([^^]*?)\".*?>/", $model->content, $images);
         $images = isset($images[0][0]) ? $images[0][0] : '';
         $content = mb_substr(strip_tags($model->content), 0, 140, 'utf-8') . '... ' . Html::a(Yii::t('app', 'View Details'), $model->url) . '<br>' . $images;
         $postData = ['{title}' => $title, '{content}' => $content];
         Feed::addFeed('blog', $postData);
         return $this->redirect(['/home/post']);
     }
     return $this->render('create', ['model' => $model]);
 }
Example #3
0
 /**
  * Creates a new Post model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $this->layout = '@app/modules/user/views/layouts/user';
     $model = new Post();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->userData->updateKey('post_count', Yii::$app->user->id);
         Yii::$app->userData->updateKey('feed_count', Yii::$app->user->id);
         //插入记录(Feed)
         $title = Html::a(Html::encode($model->title), $model->url);
         preg_match_all("/<[img|IMG].*?src=\"([^^]*?)\".*?>/", $model->content, $images);
         $summary = mb_substr(strip_tags($model->content), 0, 140, 'utf-8') . '... ' . Html::a(Yii::t('app', 'View Details'), $model->url) . '<br>' . $images[0][0];
         $postData = ['{title}' => $title, '{summary}' => $summary];
         Feed::addFeed('blog', serialize($postData));
         return $this->redirect(['/home/post']);
     }
     return $this->render('create', ['model' => $model]);
 }