/** * Get attribute columns for index and view page * * @param $page * * @return array */ public function getColumns($page) { switch ($page) { case 'index': return [['class' => 'yii\\grid\\SerialColumn'], 'label', 'alias', ['attribute' => 'category_id', 'filter' => ArticleCategory::getItems(), 'value' => function (self $data) { return isset($data->category->label) ? $data->category->label : ''; }], 'date', 'tags', 'views', 'published:boolean', 'position', ['class' => 'yii\\grid\\ActionColumn']]; break; case 'view': return ['id', 'label', 'alias', ['attribute' => 'category_id', 'filter' => ArticleCategory::getItems(), 'value' => isset($this->category->label) ? $this->category->label : ''], ['attribute' => 'announce', 'format' => 'html'], ['attribute' => 'content', 'format' => 'html'], 'date', 'tags', 'views', 'published:boolean', 'position']; break; } return []; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ArticleCategory::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, 'published' => $this->published]); $query->andFilterWhere(['like', 'label', $this->label])->andFilterWhere(['like', 'alias', $this->alias]); return $dataProvider; }
/** * @return string */ public function getModelClass() { return ArticleCategory::className(); }