/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Kategori::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, 'id_variabel' => $this->id_variabel]); $query->andFilterWhere(['like', 'nama', $this->nama])->andFilterWhere(['like', 'keterangan', $this->keterangan]); return $dataProvider; }
<?php use yii\helpers\Html; use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $searchModel backend\models\FaktaSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Faktas'; $this->params['breadcrumbs'][] = $this->title; $wilayah = \yii\helpers\ArrayHelper::map(\common\models\Wilayah::find()->all(), 'id', 'nama'); $bulan = \yii\helpers\ArrayHelper::map(\common\models\Bulan::find()->all(), 'id', 'nama'); $variabel = \yii\helpers\ArrayHelper::map(\common\models\Variabel::find()->all(), 'id', 'nama'); $kategori = \yii\helpers\ArrayHelper::map(\common\models\Kategori::find()->all(), 'id', 'nama'); $sumberData = \yii\helpers\ArrayHelper::map(\common\models\SumberData::find()->all(), 'id', 'nama_cs'); ?> <div class="fakta-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Create Fakta', ['create'], ['class' => 'btn btn-success']); ?> </p>
/** * @return \yii\db\ActiveQuery */ public function getIdKategori() { return $this->hasOne(Kategori::className(), ['id' => 'id_kategori']); }
/** * Finds the Kategori model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Kategori the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Kategori::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }