/**
  * Get the category Model for a specific ID.
  *
  * Inside the Cat Object you can then retrieve its articles:
  *
  * ```php
  * foreach ($model->articles as $item) {
  *
  * }
  * ```
  *
  * or customize the where query:
  *
  * ```php
  * foreach ($model->getArticles()->where(['timestamp', time())->all() as $item) {
  *
  * }
  * ```
  *
  * @param integer $categoryId
  * @return \yii\web\Response|string
  */
 public function actionCategory($categoryId)
 {
     $model = Cat::findOne($categoryId);
     if (!$model) {
         return $this->goHome();
     }
     $provider = new ActiveDataProvider(['query' => $model->getArticles()]);
     return $this->render('category', ['model' => $model, 'provider' => $provider]);
 }
Exemplo n.º 2
0
 public function getCategoryName()
 {
     $catModel = Cat::find()->where(['id' => $this->cat_id])->one();
     return $catModel->title;
 }