Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CategoryRecord::find()->lang();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'lang', $this->lang])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'metaKeywords', $this->metaKeywords])->andFilterWhere(['like', 'metaDescription', $this->metaDescription]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 public function actionList($lang = null, $alias = null)
 {
     $query = EventsRecord::find()->joinWith(['category', 'images'])->lang($lang);
     $breadcrumbs = [];
     if ($alias) {
         if ($category = CategoryRecord::find()->lang()->andWhere(['alias' => $alias])->one()) {
             /** @var $category CategoryRecord */
             $breadcrumbs[] = ['label' => Language::t('blog', 'Блог'), 'url' => ['list']];
             $breadcrumbs[] = $category->title;
             $query->andWhere([CategoryRecord::tableName() . '.alias' => $alias]);
         } else {
             throw new HttpException(404);
         }
     } else {
         $breadcrumbs[] = Language::t('blog', 'Блог');
     }
     $count = $query->count();
     $pagination = new Pagination(['totalCount' => $count, 'defaultPageSize' => \Yii::$app->params['pageSize'], 'pageParam' => 'p']);
     $models = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['dateCreate' => SORT_DESC])->all();
     $categorys = CategoryRecord::find()->lang($lang)->orderBy(['title' => SORT_ASC])->all();
     return $this->render('list', ['models' => $models, 'pagination' => $pagination, 'categorys' => $categorys, 'breadcrumbs' => $breadcrumbs]);
 }