示例#1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Cms::find();
     $query->joinWith(['page']);
     $query->joinWith(['cmsposition']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     /*
     $dataProvider->setSort([
     	'attributes' => [
     		'cmsposition_name' => [
     			'asc' => ['cmsposition.name' => SORT_ASC],
     			'desc' => ['cmsposition.name' => SORT_DESC],
     			'label' => 'test'
     		],
     	]
     ]); 
     */
     $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, 'begindate' => $this->begindate, 'enddate' => $this->enddate, 'addtime' => $this->addtime, 'status' => $this->status, 'cms.pageid' => $this->page_name, 'cmspositionid' => $this->cmsposition_name, 'sort' => $this->sort]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'tag', $this->tag])->andFilterWhere(['like', 'link', $this->link])->andFilterWhere(['like', 'imgurl', $this->imgurl]);
     return $dataProvider;
 }
示例#2
0
 public function actionList()
 {
     $q = Cms::find();
     $q2 = clone $q;
     $pages = new Pagination(['totalCount' => $q2->count()]);
     $pages->pageSize = 3;
     $cms = $q->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('list', ['cms' => $cms, 'pages' => $pages]);
 }
示例#3
0
 public function actionIndex()
 {
     $main = \app\models\Cms::find()->where(['unique_name' => 'main'])->one();
     if ($main) {
         $data['content'] = $main->content;
     } else {
         $data['content'] = '';
     }
     return $this->render('home', $data);
 }