/**
  * Finds the group model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return group the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Group::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 private function getParentGroups($groupId = '')
 {
     $groups = $_dataMap = [];
     if (!$groupId) {
         $groupId = $this->Id;
     }
     $_dataMap = ArrayHelper::map(Group::find()->where(['status' => '1'])->andWhere('Id <=' . $groupId)->all(), 'Id', 'parentId');
     $groups[] = $key = $groupId;
     while ($key != 0) {
         if (isset($_dataMap[$key]) && $_dataMap[$key] != 0) {
             $groups[] = $key = $_dataMap[$key];
         } else {
             $key = 0;
         }
     }
     return $groups;
 }
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
/**
 * @var yii\web\View $this
 * @var common\models\User $model
 * @var yii\widgets\ActiveForm $form
 */
//print_r($model->groupMap);
?>
<div class="user-form">
    <?php 
$form = ActiveForm::begin();
?>
    <?php 
echo $form->field($model, 'groupMap')->checkboxList(ArrayHelper::map(\mithun\usermanage\models\Group::find()->where(['status' => '1'])->all(), 'Id', 'name'), ['class' => 'list-group', 'itemOptions' => ['class' => 'list-group-item']]);
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
        <?php 
echo Html::button('Back', ['class' => 'btn btn-default', 'onclick' => 'history.go(-1);return true;']);
?>
    </div>
    <?php 
ActiveForm::end();
?>
</div>
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getGroup()
 {
     return $this->hasOne(Group::className(), ['Id' => 'groupId']);
 }
?>

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

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

    <?php 
echo $form->field($model, 'phone')->textInput(['maxlength' => 10]);
?>
    
    <?php 
echo $form->field($model, 'groupId')->dropDownList(ArrayHelper::merge(["Select" => 'Select'], ArrayHelper::map(\mithun\usermanage\models\Group::find()->where(['status' => '1'])->all(), 'Id', 'name')));
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
        <?php 
echo Html::button('Back', ['class' => 'btn btn-default', 'onclick' => 'history.go(-1);return true;']);
?>
    </div>

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