步骤如下:
1.登录函数中存登录时间:
session('logintime',time());
2.在APP/Index/Common/common.php添加公共类:
class CheckAction extends Action {
public function __construct() {
parent::__construct();
$this->checkAdminSession();
}
public function checkAdminSession() {
// echo "happy";
//设置超时为10分
$nowtime = time();
$s_time = session('logintime');
if (($nowtime - $s_time) > 1800) {
session('logintime',null);
$this->error('当前用户未登录或登录超时,请重新登录', U('Admin/Index/index'));
} else {
session('logintime',$nowtime);
}
}
}
3.APP的每个需要检测的Action都继承上面的类:
例:
lass AnnouceAction extends CheckAction
{
public function lists(){
$username = session('agentName');
//判断是否有输入密码;
if(empty($username)){
//如果为空跳回登录页;
$this->redirect('QiXunAgent/Index/index');
}
$age=M('agentuser')->where(array('account'=>$username))->find();
$m=M('announceforman');
//加载分页类
import('ORG.Util.Page');
//计算记录总数
$condition['managerID'] = 0;
$condition['agentID'] = $age['id'];
$count = $m->where($condition)->count();
//实例化分页类
$page = new Page($count,8);
//设置主题
$page->setConfig('header','');
$page->setConfig('theme',"%totalRow% %header% 当前第 %nowPage% 页 共 %totalPage% 页 %upPage% %downPage% %first% %prePage% %linkPage% %nextPage% %end%");
//设置超链接
$this->show = $page->show();
$data = $m->where($condition)->order('datetime desc')->limit($page->firstRow.",".$page->listRows)->select();
$this->assign('data',$data);
$this->display();
}
}