public function actionIndex () { parent::_acl(); self::_updateData($_POST['Config']); $this->render('index', array ('config' => self::loadData() )); }
1.操作前判断权限:
protected function _acl ($action = false, $params = array('ajax'=>false, 'append'=>',default_index,default_home')) { $actionFormat = empty($action) ? strtolower($this->id . '_' . $this->action->id) : strtolower($action); $permission = self::_sessionGet('_adminiPermission'); if ($permission != 'administrator') { $adminiGroup = self::_sessionGet('_adminiGroupId'); $aclDb = AdminGroup::model()->find('id=:id', array ('id' => $adminiGroup )); if (! in_array($actionFormat, explode(',', strtolower($aclDb->acl) . $params['append']))) { if($params['ajax'] == false){ XUtils::message('error', '当前角色组无权限进行此操作,请联系管理员授权', $this->createUrl('index'), 20); }else{ $var['state'] = 'error'; $var['message'] = '当前角色组无权限进行此操作,请联系管理员授权'; exit(CJSON::encode($var)); } } } }
2.修改提交页面(还有刷新缓存):
private function _updateData ($data, $scope = 'base') { if (XUtils::method() == 'POST') { foreach ((array) $data as $key => $row) { $connection = Yii::app()->db->createCommand("REPLACE INTO {{config}}(`scope`, `variable`, `value`) VALUES('$scope','$key', '$row') ")->execute(); } XXcache::refresh('_config', 3600); parent::_adminiLogger(array ( 'catalog' => 'update' , 'intro' => '更新系统配置,模块:' . $this->action->id )); XUtils::message('success', '更新完成', $this->createUrl($this->action->id)); } }
3.将数据渲染到修改页面(取数据):
public function loadData () { $model = Config::model()->findAll(); foreach ($model as $key => $row) { $config[$row['variable']] = $row['value']; } return $config; }