コード例 #1
0
 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.');
     }
 }
コード例 #2
0
ファイル: PostEditForm.php プロジェクト: hysdop/YobaCMS
 public function validatePostUrl($attribute, $params)
 {
     $row = Posts::findOne(['url' => $this->url]);
     if ($row) {
         if ($row->id != $this->post_id) {
             $this->addError($attribute, 'Страница с таким URI уже существует.');
         }
     }
 }
コード例 #3
0
ファイル: CommentsWidget.php プロジェクト: hysdop/YobaCMS
 public function allow_comments()
 {
     $post = Posts::findOne($this->post_id);
     if ($post) {
         if (!$post->allow_comments) {
             return false;
         }
     } else {
         return false;
     }
     return true;
 }
コード例 #4
0
ファイル: PostsController.php プロジェクト: hogvarce/basic
 /**
  * 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.');
     }
 }
コード例 #5
0
 protected function findModelPostByAlias($alias)
 {
     if (($model = Posts::findOne(['slug' => $alias])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #6
0
ファイル: PostsController.php プロジェクト: hysdop/YobaCMS
 /**
  * Отображает новость по 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]);
 }