コード例 #1
0
ファイル: Category.php プロジェクト: Dominus77/blog
 /**
  * Возвращает модель категории.
  * @param int $id идентификатор категории
  * @throws NotFoundHttpException в случае, когда категория не найдена
  * @return Post
  */
 public function getCategory($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested post does not exist.');
     }
 }
コード例 #2
0
 public function actionBycategory($category_id)
 {
     $cat = new Category();
     $model = $cat->findOne($category_id);
     $category_title = $model->name;
     $dataProvider = new ActiveDataProvider(['query' => Post::find()->where(['status' => 1, 'category_id' => $category_id])->with('category')->orderBy('created_at DESC'), 'pagination' => ['pageSize' => 10]]);
     return $this->render('categoryindex', ['listDataProvider' => $dataProvider, 'category_title' => $category_title]);
 }
コード例 #3
0
 /**
  * Finds the Category model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Category the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }