/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Room::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]); $query->andFilterWhere(['like', 'room', $this->room])->andFilterWhere(['like', 'desciption', $this->desciption])->andFilterWhere(['like', 'photo', $this->photo])->andFilterWhere(['like', 'color', $this->color]); return $dataProvider; }
?> <div class="box box-info box-solid"> <div class="box-header"> <h3 class="box-title"><i class="fa fa-home"></i><?php echo Html::encode($this->title); ?> </h3> </div> <div class="box-body"> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('เพิ่มห้อง', ['create'], ['class' => 'btn btn-primary']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'room', ['attribute' => 'photo', 'format' => 'html', 'value' => function ($model) { return Html::img('uploads/room/' . $model->photo, ['class' => 'thumbnail', 'width' => 100]); }], ['attribute' => 'color', 'format' => 'html', 'value' => function ($model) { return '<span style="background-color:' . $model->color . ';">' . '<span style="color:' . $model->color . ';">' . $model->color . '</span></span>'; }, 'filter' => Html::activeDropDownList($searchModel, 'color', ArrayHelper::map(Room::find()->all(), 'color', 'color'), ['class' => 'form-control'])], ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div> </div>
/** * @return \yii\db\ActiveQuery */ public function getRoom() { return $this->hasOne(Room::className(), ['id' => 'room_id']); }
/** * Finds the Room model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Room the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Room::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }