public function actionSingle()
 {
     $model = new CommentForm();
     $blog = Blog::getInstance();
     $uri = \Yii::$app->request->get('uri');
     $article = Articles::findOne(['id' => \Yii::$app->request->get('id')]);
     if (!$article) {
         \Yii::$app->session->setFlash('articleNotFound', 'warning');
         // Look at UrlManager configurations
         // Real address is['/blog/category?uri=' . $uri]
         return $this->redirect(['/category/' . $uri], 302);
     }
     $articleCatUri = $article->category->uri;
     $articleId = $article->id;
     if ($articleCatUri != $uri) {
         // Look at UrlManager configurations
         // Real address is ['/blog/single?uri=' . $articleCatUri . '&id=' . $articleId]
         return $this->redirect(['/category/' . $articleCatUri . '/' . $articleId], 302);
     }
     if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
         $model->article_id = $articleId;
         $answer = $model->addComment() ? ['name' => 'commentSuccessSending', 'type' => 'success'] : ['name' => 'commentWarningSending', 'type' => 'error'];
         \Yii::$app->session->setFlash($answer['name'], $answer['type']);
         return $this->refresh();
     }
     $data = $blog->getComments($articleId);
     return $this->render('single', ['article' => $article, 'model' => $model, 'data' => $data]);
 }
 /**
  * Finds the Articles model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Articles the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Articles::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Сторінки, яку Ви шукаєте не існує.');
     }
 }
Beispiel #3
0
 /**
  * Finds the Articles model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Articles the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Articles::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }