Exemple #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;
 }
Exemple #2
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);
 }
Exemple #3
0
 /**
  * Finds the Cms model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Cms the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Cms::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #4
0
 public function actionDelete($id)
 {
     $cms = Cms::findOne($id);
     $cms->delete();
     return $this->redirect('index.php?r=cms/list');
 }