/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Hospital::find()->assignment();
     $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', 'code', $this->code])->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
/* @var $this yii\web\View */
/* @var $model backend\models\HospitalAssignment */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="hospital-assignment-form">

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

    <?php 
echo $form->field($model, 'user_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(User::find()->all(), 'id', 'username'), 'options' => ['placeholder' => 'เลือกผู้ใช้งาน ...'], 'pluginOptions' => ['allowClear' => true]]);
?>

    <?php 
echo $form->field($model, 'hospital_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Hospital::find()->all(), 'id', 'name'), 'options' => ['placeholder' => 'เลือกผู้ใช้งาน ...'], 'pluginOptions' => ['allowClear' => true]]);
?>

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

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

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

use yii\helpers\Html;
use common\models\Hospital;
/* @var $this yii\web\View */
/* @var $model common\models\EvauateScore */
$this->title = 'ระบบประเมินผล';
$this->params['breadcrumbs'][] = ['label' => 'สถานพยาบาลที่ได้รับมอบหมาย', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="evauate-score-create">
  <div class="page-header" style="margin-bottom:60px;">
    <h1><?php 
echo Html::encode($this->title);
?>
 <small> : <?php 
echo @Hospital::findOne($hospital_id)->name;
?>
</small></h1>
  </div>

    <?php 
echo $this->render('_form', ['models' => $models, 'hospital_id' => $hospital_id, 'group_id' => $group_id, 'sumTheMust' => $sumTheMust, 'sumTheBest' => $sumTheBest]);
?>

</div>