Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Keluarga::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     $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;
     }
     $dataProvider->query->joinWith(['kepalaKeluarga' => function ($q) {
         $q->from('base');
     }]);
     // grid filtering conditions
     $query->andFilterWhere(['tanggal_terbit' => $this->tanggal_terbit, 'tanggal_pembaruan' => $this->tanggal_pembaruan, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'id', $this->id]);
     $query->andFilterWhere(['like', 'tanggal_terbit', $this->tanggal_terbit]);
     $query->andFilterWhere(['like', 'base.nama', $this->kepala_keluarga]);
     $query->andFilterWhere(['like', 'status', $this->status]);
     return $dataProvider;
 }
Example #2
0
 public function actionNoKkList($q = null, $id = null)
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $out = ['results' => ['id' => '', 'text' => '']];
     if (!is_null($q)) {
         $query = new \yii\db\Query();
         $query->select('id, id AS text')->from('keluarga')->where(['like', 'id', $q])->limit(20);
         $command = $query->createCommand();
         $data = $command->queryAll();
         $out['results'] = array_values($data);
     } elseif ($id > 0) {
         $out['results'] = ['id' => $id, 'text' => Keluarga::find($id)->id];
     }
     return $out;
 }
 /**
  * Finds the Keluarga model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Keluarga the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Keluarga::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }