/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $this->checkAccess('adminrole.update'); $model = $this->loadModel($id); if ($id == 1 || $model->title == '超级管理员' || $model->actions == '*') { $this->redirect(array('admin')); } $array = explode(',', $model->actions); $allActions = AdminActions::getAllActions(); foreach ($allActions as $k => $action) { foreach ($array as $item) { if ($action['action'] == $item) { $allActions[$k]['selected'] = "checked"; } } } // 下拉列表 Tree::$arr = $allActions; $tree = Tree::getTree(0, "<label class='checkbox'><input type='checkbox' name='AdminRole[actions][]' id='AdminRole_actions_\$id' data-id='\$id' data-parent-id='\$parent_id' value='\$action' \$selected><label for='AdminRole_actions_\$id'>\$spacer\$name</label></label>", -1, true); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); if (isset($_POST['AdminRole'])) { $model->attributes = $_POST['AdminRole']; $model->actions = implode(',', $model->actions); if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('update', array('model' => $model, 'tree' => $tree)); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $this->checkAccess('adminactions.update'); $model = $this->loadModel($id); $allActions = AdminActions::getAllActions($model->parent_id, 'selected'); // 下拉列表 $tree = '<option value="0">顶级动作</option>'; Tree::$arr = $allActions; $tree .= Tree::getTree(0, "<option value=\$id \$selected>\$spacer\$name</option>", $model->parent_id - 1, true); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); if (isset($_POST['AdminActions'])) { $model->attributes = $_POST['AdminActions']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('update', array('model' => $model, 'tree' => $tree)); }