/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Pages::find(); $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, 'page' => $this->page, 'status' => $this->status, 'order' => $this->order]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'page', $this->page])->andFilterWhere(['like', 'keyword', $this->keyword])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
public function actionIndex() { $model = Rooms::find()->where(['status' => 1])->all(); $page = Pages::find()->where(['page' => 'rooms'])->one(); return $this->render('index', ['model' => $model, 'page' => $page]); }
use yii\grid\GridView; use app\components\grid\SetColumn; use app\modules\hotel\models\Pages; /* @var $this yii\web\View */ /* @var $searchModel app\modules\admin\models\search\PagesSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Pages'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="pages-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Create Pages', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'page', 'title', ['attribute' => 'created_at', 'format' => ['date', 'd MMMM yyyy HH:mm']], ['attribute' => 'updated_at', 'format' => ['date', 'd MMMM yyyy HH:mm']], ['class' => SetColumn::className(), 'filter' => Pages::getStatusesArray(), 'attribute' => 'status', 'name' => 'statusName', 'cssCLasses' => [Pages::STATUS_PUBLISH => 'success', Pages::STATUS_UNPUBLISHED => 'default']], ['class' => 'yii\\grid\\ActionColumn', 'options' => ['width' => '100']]]]); ?> </div>
public function actionContact() { $pages = Pages::find()->where(['page' => 'contact'])->one(); return $this->render('contact', ['page' => $pages]); }
/** * Finds the Pages model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Pages the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Pages::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }