/** * 用户管理页面 * @return [type] [description] */ public function userPage() { $user_mod = M('User'); $pagnums = $_GET['pagnums']; $keywords = $_GET['keywords']; $count = $user_mod->count(); $page = new \Think\Page($count, $pagnums); $show = $page->show(); //memcache缓存 $cache = Cache::getInstance(); $list = $cache->get('userSet'); if (!$list) { $user_res = $user_mod->select(); $cache->set('userSet', $user_res); $list = $cache->get('userSet'); } $list = array_slice($list, $page->firstRow, $page->listRows); //搜索 if ($keywords) { $list = $user_mod->where("username like '%{$keywords}%'")->limit($page->firstRow . ',' . $page->listRows)->select(); $count = $user_mod->where("username like '%{$keywords}%'")->count(); } $page = new \Think\Page($count, $pagnums); $show = $page->show(); //分页输出 $this->assign('pagnums', $pagnums); $this->assign('list', $list); $this->assign('show', $show); $this->assign('currentpath', 'Home / User'); $this->display(); }
public function cache() { if (isset($_GET['type'])) { $Dir = new \Dir(); $cache = D('Common/Cache'); $type = I('get.type'); switch ($type) { case "template": //删除缓存目录下的文件 $Dir->del(RUNTIME_PATH); $Dir->delDir(RUNTIME_PATH . "Cache/"); $Dir->delDir(RUNTIME_PATH . "Temp/"); //更新开启其他方式的缓存 \Think\Cache::getInstance()->clear(); $this->success("模板缓存清理成功!", U('Index/cache')); break; case "logs": $Dir->delDir(RUNTIME_PATH . "Logs/"); $this->success("站点日志清理成功!", U('Index/cache')); break; default: $this->error("请选择清楚缓存类型!"); break; } } else { $this->display(); } }
protected function _initialize() { if (!isset($_SESSION['ht_admin'])) { $this->error('没有登录', '/?c=Login'); } $options = array('host' => C('MEMCACHE_HOST'), 'port' => C('MEMCACHE_PORT'), 'timeout' => 14400, 'persistent' => false); $Cache = \Think\Cache::getInstance('memcache', $options); $role_id = $Cache->get('role_id_' . session_id()); if ($role_id < 0) { $role_id = $_SESSION['ht_admin']['role_id']; } //echo $role_id; $role = M('Role')->where(array('id' => $role_id))->find(); if (!$role) { //$this->error('角色已经不存在了','/Login'); } $this->classname_arr = unserialize($role['classname']); $this->module_arr = unserialize($role['module']); $this->method_arr = unserialize($role['method']); //var_dump($this->module_arr);exit; $this->assign('classname_arr', $this->classname_arr); $this->assign('module_arr', $this->module_arr); $this->assign('method_arr', $this->method_arr); //echo CONTROLLER_NAME.'='.ACTION_NAME; }
function auth() { $login_user = I('post.login_user'); $login_pass = I('post.login_pass'); $vcode = I('post.vcode'); $verify = new \Think\Verify(); //$flag = $verify->check($vcode); $flag = true; if ($flag == false) { $this->error('验证码错误', '/?c=Login'); } $row = M('AdminUser')->where(array('login_user' => $login_user))->find(); if (!$row) { $this->error('用户不存在', '/?c=Login'); } if ($row['status'] == 1) { $this->error('用户被禁用', '/?c=Login'); } if (md5($login_pass) != $row['login_pass']) { $this->error('密码错误', '/?c=Login'); } $data['last_login_time'] = time(); $data['login_num'] = $row['login_num'] + 1; M('AdminUser')->where(array('id' => $row['id']))->save($data); $_SESSION['ht_admin']['id'] = $row['id']; $_SESSION['ht_admin']['username'] = $row['login_user']; $_SESSION['ht_admin']['role_id'] = $row['role_id']; $this->success('恭喜进入系统后台', '/'); //import("Think/Cache"); $options = array('host' => C('MEMCACHE_HOST'), 'port' => C('MEMCACHE_PORT'), 'timeout' => 14400, 'persistent' => false); $Cache = \Think\Cache::getInstance('memcache', $options); $Cache->set(session_id(), time()); $Cache->set('id_' . session_id(), $row['id'], 14400); $Cache->set('name_' . session_id(), $row['login_user'], 14400); $Cache->set('role_id_' . session_id(), $row['role_id'], 14400); //echo $Cache->get('id_'.session_id());exit; //$Cache->set('name_''.$row['id'],$row['login_user']); //$Cache->set('role_id_'.$row['id'],$row['role_id']); //var_dump($flag);exit; /*if($login_user!='yeeuo' || $login_pass!='yeeuo!@#$%^') { $this->error('用户名或密码错误'); } $_SESSION['yeeuo_admin']['username']='******'; $this->success('恭喜您进入系统后台','/');*/ }
/** * 生成查询SQL * @access protected * @param array $options 表达式 * @return string */ protected function buildSelectSql($options = array()) { static $cache; if (isset($options['page'])) { // 根据页数计算limit list($page, $listRows) = $options['page']; $page = $page > 0 ? $page : 1; $listRows = $listRows > 0 ? $listRows : (is_numeric($options['limit']) ? $options['limit'] : 20); $offset = $listRows * ($page - 1); $options['limit'] = $offset . ',' . $listRows; } if (C('DB_SQL_BUILD_CACHE')) { // SQL创建缓存 if (!isset($cache)) { $cache = \Think\Cache::getInstance('', array('expire' => 0, 'length' => C('DB_SQL_BUILD_LENGTH'), 'queue' => C('DB_SQL_BUILD_QUEUE'))); } $key = md5(serialize($options)); $value = $cache->get($key); if (false !== $value) { return $value; } } $sql = $this->parseSql($this->selectSql, $options); if (isset($key)) { // 写入SQL创建缓存 $cache->set($key, $sql); } return $sql; }
public function cache() { if (isset($_GET['type'])) { $Dir = new \Dir(); $cache = D('Common/Cache'); $type = I('get.type'); set_time_limit(0); switch ($type) { case "site": //开始刷新缓存 $stop = I('get.stop', 0, 'intval'); if (empty($stop)) { try { //已经清除过的目录 $dirList = explode(',', I('get.dir', '')); //删除缓存目录下的文件 $Dir->del(RUNTIME_PATH); //获取子目录 $subdir = glob(RUNTIME_PATH . '*', GLOB_ONLYDIR | GLOB_NOSORT); if (is_array($subdir)) { foreach ($subdir as $path) { $dirName = str_replace(RUNTIME_PATH, '', $path); //忽略目录 if (in_array($dirName, array('Cache', 'Logs'))) { continue; } if (in_array($dirName, $dirList)) { continue; } $dirList[] = $dirName; //删除目录 $Dir->delDir($path); //防止超时,清理一个从新跳转一次 $this->assign("waitSecond", 200); $this->success("清理缓存目录[{$dirName}]成功!", U('Index/cache', array('type' => 'site', 'dir' => implode(',', $dirList)))); exit; } } //更新开启其他方式的缓存 \Think\Cache::getInstance()->clear(); } catch (Exception $exc) { } } if ($stop) { $modules = $cache->getCacheList(); //需要更新的缓存信息 $cacheInfo = $modules[$stop - 1]; if ($cacheInfo) { if ($cache->runUpdate($cacheInfo) !== false) { $this->assign("waitSecond", 200); $this->success('更新缓存:' . $cacheInfo['name'], U('Index/cache', array('type' => 'site', 'stop' => $stop + 1))); exit; } else { $this->error('缓存[' . $cacheInfo['name'] . ']更新失败!', U('Index/cache', array('type' => 'site', 'stop' => $stop + 1))); } } else { $this->success('缓存更新完毕!', U('Index/cache')); exit; } } $this->success("即将更新站点缓存!", U('Index/cache', array('type' => 'site', 'stop' => 1))); break; case "template": //删除缓存目录下的文件 $Dir->del(RUNTIME_PATH); $Dir->delDir(RUNTIME_PATH . "Cache/"); $Dir->delDir(RUNTIME_PATH . "Temp/"); //更新开启其他方式的缓存 \Think\Cache::getInstance()->clear(); $this->success("模板缓存清理成功!", U('Index/cache')); break; case "logs": $Dir->delDir(RUNTIME_PATH . "Logs/"); $this->success("站点日志清理成功!", U('Index/cache')); break; default: $this->error("请选择清楚缓存类型!"); break; } } else { $this->display(); } }
/** * 菜单排序 * * @author huajie <*****@*****.**> */ public function sort() { if (IS_GET) { $ids = I('get.ids'); $pid = I('get.pid'); // 获取排序的数据 $map = array('status' => array('gt', -1)); if (!empty($ids)) { $map['id'] = array('in', $ids); } else { if ($pid !== '') { $map['pid'] = $pid; } } $list = M('system_menu')->where($map)->field('id,title')->order('sort asc,id asc')->select(); $this->assign('list', $list); $this->meta_title = '菜单排序'; $this->display(); } elseif (IS_POST) { $ids = I('post.ids'); $ids = explode(',', $ids); foreach ($ids as $key => $value) { $res = M('system_menu')->where(array('id' => $value))->setField('sort', $key + 1); } if ($res !== false) { $cache = \Think\Cache::getInstance(); $cache->clear(); $this->success('排序成功!'); } else { $this->error('排序失败!'); } } else { $this->error('非法请求!'); } }
public function _initialize() { $this->redis = Cache::getInstance('Redis'); }
/** * 缓存管理 * * @param mixed $name 缓存名称,如果为数组表示进行缓存设置 * @param mixed $value 缓存值 * @param mixed $options 缓存参数 * * @return mixed */ function S($name, $value = '', $options = null) { static $cache = ''; // 缓存操作的同时初始化 if (is_array($options)) { $type = isset($options['type']) ? $options['type'] : ''; $cache = Cache::getInstance($type, $options); } else { if (is_array($name)) { $type = isset($name['type']) ? $name['type'] : ''; $cache = Cache::getInstance($type, $name); return $cache; } else { if (empty($cache)) { $cache = Cache::getInstance(); } } } // 获取缓存 if ($value === '') { return $cache->get($name); } else { if (is_null($value)) { return $cache->rm($name); } else { $expire = is_numeric($options) ? $options : NULL; return $cache->set($name, $value, $expire); } } }