public function actionGetRoleList()
 {
     $role = new Role();
     $roleInfos = $role->findAll(array('select' => 'rid,rname'));
     $ret = array();
     foreach ($roleInfos as $role) {
         $ret[] = $role->getAttributes();
     }
     echo json_encode($ret);
 }
示例#2
0
 public function actionList()
 {
     $page = isset($_GET['id']) ? intval($_GET['id']) : 1;
     $list = array();
     $criteria = new CDbCriteria(array('order' => 'id ASC'));
     $roles = new Role();
     $count = $roles->count($criteria);
     $pager = new CPagination($count);
     $pager->pageSize = Yii::app()->params['postsPerPage'];
     $pager->setCurrentPage($page - 1);
     $pager->applyLimit($criteria);
     $list = $roles->findAll($criteria);
     $this->render('list', array('r' => Yii::app()->request->baseUrl . '/', 'pages' => $pager, 'list' => $list));
 }
 public function actionEdit()
 {
     //echo "<pre>";var_dump($_REQUEST);exit;
     $usr = new User();
     $role = new Role();
     $usrInfo = array();
     $label = '';
     foreach ($_REQUEST as $k => $v) {
         $_REQUEST[$k] = trim($v);
     }
     // 获取role列表
     $roleInfos = $role->findAll(array('select' => 'rid,rname'));
     // 过滤超极管理员
     foreach ($roleInfos as $role) {
         if ($role['rname'] != 'superman') {
             $roles[] = $role;
         }
     }
     // var_dump($_REQUEST); exit;
     //
     if (isset($_REQUEST['id']) && $_REQUEST['id'] != '') {
         // 修改
         $usrInfo = $usr->getUserWithRole('uid=:uid', array(':uid' => $_REQUEST['id']));
         $usrInfo = $usrInfo[0];
         if (isset($_REQUEST['modify'])) {
             $usr->updateByPk($_REQUEST['id'], array('uname' => $_REQUEST['name'], 'email' => $_REQUEST['email'], 'pwd' => Login::pwdEncry($_REQUEST['pwd']), 'rid' => $_REQUEST['rid']));
             $this->redirect('/main/user/list');
         }
     } elseif (!empty($_REQUEST['name'])) {
         // 新增
         $usrInfo = $usr->getUserWithRole('uname=:name', array(':name' => $_REQUEST['name']));
         //var_dump($usrInfo);exit;
         if (!empty($usrInfo)) {
             $this->render('edit', array('roles' => $roles, 'entity' => $usrInfo[0], 'label' => 'has_usr'));
             exit;
         }
         if (isset($_REQUEST['modify'])) {
             $usr->uname = $_REQUEST['name'];
             $usr->email = $_REQUEST['email'];
             $usr->pwd = Login::pwdEncry($_REQUEST['pwd']);
             $usr->rid = $_REQUEST['rid'];
             $usr->save();
             $this->redirect('/main/user/list');
         }
     }
     $this->render('edit', array('entity' => $usrInfo, 'roles' => $roles, 'label' => $label));
 }