/**
 * Creates data provider instance with search query applied
 *
 * @param array $params
 *
 * @return ActiveDataProvider
 */
 public function search($params)
 {
     $query = BlogCategory::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     return $dataProvider;
 }
 protected function findBlogCategory($slug)
 {
     /*TODO: Clean Messy Code*/
     $blogCategoryCurrentLanguage = BlogCategory::find()->joinWith('translations')->where(['blog_category_lang.slug' => $slug])->andWhere(['blog_category_lang.language' => Yii::$app->language])->one();
     $blogCategory = $blogCategoryCurrentLanguage;
     /*Fallback language*/
     if (!isset($blogCategory)) {
         $blogCategory = BlogCategory::find()->joinWith('translations')->where(['blog_category_lang.slug' => $slug])->andWhere(['blog_category_lang.language' => Yii::$app->params['fallbackLanguage']])->one();
         if (isset($blogCategory) && $slug != $blogCategory->slug) {
             $blogCategory = $blogCategoryCurrentLanguage;
         }
     }
     /*Main language*/
     if (!isset($blogCategory)) {
         $blogCategory = BlogCategory::find()->joinWith('translations')->where(['blog_category_lang.slug' => $slug])->andWhere(['blog_category_lang.language' => Yii::$app->params['appMainLanguage']])->one();
         if (isset($blogCategory) && $slug != $blogCategory->slug) {
             $blogCategory = $blogCategoryCurrentLanguage;
         }
     }
     if (!isset($blogCategory)) {
         throw new HttpException(404, Yii::t('app', 'The requested page does not exist.'));
     }
     return $blogCategory;
 }
Exemple #3
0
<div class="row">
  <div class="col-sm-8">
    <div class="blog-content">
      <?php 
echo $content;
?>
    </div>
  </div>
  <div class="col-sm-4">
    <div class="blog-sidebar">
      <h3><?php 
echo Yii::t('blog', 'Categories');
?>
</h3>
      <?php 
$categories = BlogCategory::find()->all();
?>
      <ul>
        <?php 
foreach ($categories as $category) {
    ?>
<li><?php 
    echo Html::a($category->name, $category->url);
    ?>
</li><?php 
}
?>
      </ul>
      <h3><?php 
echo Yii::t('blog', 'Tags');
?>