/** * 修改用户信息 */ public function actionEdit($id) { if (empty($id)) { return; } $user = IMUsers::model()->findByPk($id); if (Yii::app()->request->isPostRequest) { $data = Yii::app()->request->getPost('data'); $file = $this->image(); $user->attributes = $data; if ($user->pwd != $data['pwd']) { $user->pwd = md5($data['pwd']); } if ($_FILES['data']['tmp_name']['mod_avatar']) { $user->avatar = $this->_upload($file); } $user->departId = $data['departId']; $user->status = $data['status']; $time = time(); $user->updated = $time; if ($user->update()) { $this->showAlert('success', '修改成功'); //更新用户之后更新用户缓存 $this->getUserCache(); } else { $this->showAlert('fail', '修改失败'); } } $departs = Yii::app()->cache->get('cache_depart'); $this->render('add', array('data' => $user, 'departs' => $departs)); }
/** * 获取用户缓存 * */ public function getUserCache() { $users = IMUsers::model()->findAll(array('condition' => 'status = 0')); foreach ($users as $k => $v) { $cache[$k]['userId'] = $v->id; $cache[$k]['title'] = $v->title; $cache[$k]['uname'] = $v->uname; } if (!empty($cache)) { Yii::app()->cache->set('cache_user', $cache); } return $cache; }