public function actionArticle($id) { $query = Posts::findOne(['id' => $id]); if ($query !== null) { return $this->render('article', ['article' => $query]); } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function validatePostUrl($attribute, $params) { $row = Posts::findOne(['url' => $this->url]); if ($row) { if ($row->id != $this->post_id) { $this->addError($attribute, 'Страница с таким URI уже существует.'); } } }
public function allow_comments() { $post = Posts::findOne($this->post_id); if ($post) { if (!$post->allow_comments) { return false; } } else { return false; } return true; }
/** * Finds the Posts model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Posts the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Posts::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
protected function findModelPostByAlias($alias) { if (($model = Posts::findOne(['slug' => $alias])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Отображает новость по URL * @return string * @throws HttpException */ public function actionPost() { $this->layout = 'main'; $post = Posts::findOne(['url' => $_GET['url'], 'active' => true]); if (!$post) { throw new HttpException(404, 'Страница не существует.'); } return $this->render('post', ['post' => $post]); }