/** * Displays a single Journal model. * @param integer $id * @return mixed */ public function actionView($id) { //var_dump($notify); die(); $searchModel = new JournalSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $model = $this->findModel($id); $comment = new Comment(); $comment->user_id = \Yii::$app->user->id; $commentProvider = new ActiveDataProvider(['query' => Comment::find()->where(['journal_id' => $id])]); Yii::$app->notification->viewer($id); if ($comment->load(Yii::$app->request->post())) { $comment->journal_id = $id; $comment->time = date('Y-m-d H:i:s'); if ($comment->save()) { Yii::$app->notification->notify($model->entry, $model, $comment->user, 'comment', $model->shared_with . ',' . $model->user_id); Yii::$app->session->setFlash('success', 'Comment posted successfully.'); return Yii::$app->getResponse()->redirect(array('/journal/view/' . $model->id)); } else { exit; } } else { if (Yii::$app->request->isAjax) { return $this->renderAjax('view', ['model' => $model, 'comment' => $comment, 'dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'commentProvider' => $commentProvider]); } else { return $this->render('view', ['model' => $model, 'comment' => $comment, 'dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'commentProvider' => $commentProvider]); } } }
public function actionIndex() { $searchModel = new JournalSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams, Yii::$app->session['filter']); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }