/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Barangay::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(['barangay_id' => $this->barangay_id, 'district_id' => $this->district_id]);
     $query->andFilterWhere(['like', 'barangay', $this->barangay]);
     return $dataProvider;
 }
/* @var $form yii\widgets\ActiveForm */
?>

<div class="school-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'school_name')->textInput(['maxlength' => true]);
?>


     <?php 
$barangay = Barangay::find()->all();
$listData = ArrayHelper::map($barangay, 'barangay_id', 'barangay');
echo $form->field($model, 'barangay_id')->dropDownList($listData, ['prompt' => 'Select your Barangay']);
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>

</div>
 /**
  * Finds the Barangay model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Barangay the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Barangay::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBarangays()
 {
     return $this->hasMany(Barangay::className(), ['district_id' => 'district_id']);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBarangay()
 {
     return $this->hasOne(Barangay::className(), ['barangay_id' => 'barangay_id']);
 }