public function actionUpdate($id) { $model = Notice::findOne($id); if ($model->load(Yii::$app->request->post())) { // 获取用户输入的数据,验证并保存 $rids = $model->rids; $model->rids = ',' . implode(',', $model->rids) . ','; if ($model->save()) { $this->redirect('/notice/index'); } } $rids = $model->rids; $model->rids = explode(',', $rids); $roles = Role::findBySql('SELECT * FROM ' . Role::tableName() . ' where id > 1')->all(); return $this->render('update', array('model' => $model, 'roles' => $roles)); }
public function actionUpdate($id) { $model = User::findOne($id); if (empty($model)) { throw new HttpException(404, '用户不存在!'); } if ($this->user->rid > 1 && $model->rid == 2) { throw new MethodNotAllowedHttpException('权限不够!'); } if ($model->load(Yii::$app->request->post())) { // 获取用户输入的数据,验证并保存 if ($model->save()) { $this->redirect('/user/index'); } } $roles = Role::findBySql('SELECT * FROM ' . Role::tableName() . ' where id > 1')->all(); return $this->renderAjax('update', array('model' => $model, 'roles' => $roles)); }