/** * Creates a new Feed model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Feed(); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->userData->updateKey('feed_count', Yii::$app->user->id); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionIndex() { if (Yii::$app->user->isGuest) { $this->redirect(['/explore/index']); } $model = $this->findModel(); $newFeed = new Feed(); if ($newFeed->load(Yii::$app->request->post()) && $newFeed->save()) { Yii::$app->userData->updateKey('feed_count', Yii::$app->user->id); return $this->refresh(); } $query = new Query(); $query = $query->select('p.id, p.user_id, p.content, p.feed_data, p.template, p.created_at, u.username, u.avatar')->from('{{%home_feed}} as p')->join('LEFT JOIN', '{{%user_follow}} as f', 'p.user_id=f.people_id')->join('LEFT JOIN', '{{%user}} as u', 'u.id=p.user_id')->where('p.user_id=:user_id OR f.user_id=:user_id', [':user_id' => $model->id])->orderBy('p.created_at DESC'); $pages = Tools::Pagination($query); return $this->render('index', ['model' => $model, 'newFeed' => $newFeed, 'feeds' => $pages['result'], 'pages' => $pages['pages']]); }
/** * Creates a new Feed model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($id = null) { $model = new Feed(); $model->setScenario('repost'); if ($id != null && $model->load(Yii::$app->request->post())) { $id = intval($id); $query = new Query(); $feed = $query->select('f.content, f.feed_data, f.template, u.username')->from('{{%home_feed}} as f')->join('LEFT JOIN', '{{%user}} as u', 'u.id=f.user_id')->where('f.id=:id', [':id' => $id])->one(); $postData = ['{comment}' => $model->content, '{content}' => $feed['content'], '{username}' => Html::a($feed['username'], ['/user/view', 'id' => $feed['username']]), '{feed_data}' => unserialize($feed['feed_data']), '{template}' => $feed['template']]; Feed::addFeed('repost', $postData); Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Create successfully.')); return $this->redirect(['/user/dashboard']); } $model->setScenario('create'); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->userData->updateKey('feed_count', Yii::$app->user->id); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }