<?php $form = ActiveForm::begin(); ?> <?php $user = new common\models\User(); ?> <?php $dept = new common\models\Departments(); ?> <?php $dept2 = \common\models\Departments::find()->all(); ?> <?php $dept3count = \common\models\Assignroledetail::find()->where(['assignid' => $model->recid])->count(); $dept3 = \common\models\Assignroledetail::find()->where(['assignid' => $model->recid])->all(); ?> <?php $role = new common\models\Roles(); ?> <?php echo $form->field($model, 'description')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'userid')->dropDownList(ArrayHelper::map($user->find()->all(), 'id', 'fname')); ?>
/** * Updates an existing Assignroles model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { //echo var_dump($_POST['menu']); if (!empty($_POST['menu'])) { $dept = $_POST['menu']; } else { $dept = null; } if (count($dept) > 0 && $_POST['Assignroles']['roleid'] == 1) { \common\models\Assignroledetail::deleteAll(['assignid' => $model->recid]); foreach ($dept as $id) { $deptrole = new \common\models\Assignroledetail(); $deptrole->departmentid = $id; $deptrole->roleid = $_POST['Assignroles']['roleid']; $deptrole->assignid = $model->recid; if ($deptrole->save()) { //echo "ok"; //return; } } } else { \common\models\Assignroledetail::deleteAll(['assignid' => $model->recid]); $deptrole = new \common\models\Assignroledetail(); $deptrole->departmentid = $id; $deptrole->roleid = $_POST['Assignroles']['roleid']; $deptrole->assignid = $model->recid; if ($deptrole->save()) { //echo "ok"; //return; } } return $this->redirect(['view', 'id' => $model->recid]); } else { return $this->render('update', ['model' => $model]); } }