示例#1
0
文件: Article.php 项目: tolik505/bl
 /**
  * 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 [];
 }
示例#2
0
 /**
  * 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;
 }
示例#3
0
 /**
  * @return string
  */
 public function getModelClass()
 {
     return ArticleCategory::className();
 }