/** * Updates an existing User 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); $assignments = AuthAssignment::findAll(['user_id' => $id]); $roles = []; if ($model->load(Yii::$app->request->post()) && $model->save()) { // $this->applyAssignments($roles, $id); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'roles' => $assignments]); } }
?> </h1> <p> <?php echo Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']); ?> <?php echo Html::a('Delete', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Are you sure you want to delete this item?', 'method' => 'post']]); ?> <?php if (Yii::$app->user->can('admin')) { echo Html::a('Изменить пароль', ['password-change', 'id' => $model->id], ['class' => 'btn btn-primary']); } ?> </p> <?php $status = User::getStatusName($model->status); echo DetailView::widget(['model' => $model, 'attributes' => ['id', 'username', 'name', 'email:email', ['attribute' => 'status', 'format' => 'raw', 'value' => $model->status == 10 ? '<span class="label label-success">' . $status . '</span>' : '<span class="label label-danger">' . $status . '</span>'], ['attribute' => 'created_at', 'value' => date('d-M-Y H:i:s', $model->created_at)], ['attribute' => 'updated_at', 'value' => date('d-M-Y H:i:s', $model->updated_at)]]]); echo Html::tag('p', 'Назначенные роли'); $auth = AuthAssignment::findAll(['user_id' => $model->id]); $assignment = []; foreach ($auth as $item) { $assignment[] = $item->item_name; } echo Html::listBox('roles', null, $assignment); ?> </div>