public function execute() { $page = $this->context->get('page'); $page = max(intval($page), 1); $page_size = $this->configHandle->get('page_size'); if (empty($page_size)) { $page_size = 25; } $param['limit'] = $page_size; $param['offset'] = ($page - 1) * $page_size; $param['op'] = $this->context->get('op'); $param['gid'] = $this->context->post('gid'); $param['q'] = $this->context->post('q'); $param['field'] = $this->context->post('field'); // userid $uid = $this->data['uid']; $addressBookService = new AddressBookService(); // 取当前用户通讯录的所有分组 $this->data['groups'] = $addressBookService->getAllGroups($uid); $this->data['data'] = $addressBookService->getAddressBookListByUserId($uid, $param); $count = $this->data['data']['count']; // 分页 :page 会自动被替换掉 $base_url = LtObjectUtil::singleton('LtUrl')->generate('Default', 'Index', array('page' => ':page')); $pagination = new LtPagination(); $pagination->init(); $this->data['pages'] = $pagination->pager($page, $count, $base_url); // 页面标题 $this->data['title'] = 'addressbook'; // 入口文件url路径 $this->data['baseurl'] = $this->configHandle->get('baseurl'); }
/** * 最常用的使用方式 */ public function testMostUsedWay() { $pagination = new LtPagination(); /** * 基本配置,默认分页样式 */ $conf['default']['per_page'] = 25; //每个页面中希望展示的项目数量 $conf['default']['num_links_show'] = 9; //数字链接显示数量 $conf['default']['num_point_start_end'] = 2; //“点”前边和后边的链接数量 /** * 是否显示上一页,下一页... */ $conf['default']['show_first'] = true; $conf['default']['show_prev'] = true; $conf['default']['show_next'] = true; $conf['default']['show_last'] = true; $conf['default']['show_goto'] = false; $conf['default']['show_info'] = false; $conf['default']['show_point'] = true; $conf['default']['show_empty_button'] = false; /** * 上一页,下一页...的显示文字内容 */ $conf['default']['first_text'] = 'First'; $conf['default']['prev_text'] = 'Prev'; $conf['default']['next_text'] = 'Next'; $conf['default']['last_text'] = 'Last'; $conf['default']['point_text'] = '...'; /** * 生成html代码部分, :url表示生成链接 */ $conf['default']['full_tag_open'] = '<div class="pages">'; $conf['default']['full_tag_close'] = '</div>'; $conf['default']['num_tag_open'] = ''; $conf['default']['num_tag_close'] = ''; $conf['default']['link_tag_open'] = '<a href=":url">'; $conf['default']['link_tag_close'] = '</a>'; $conf['default']['link_tag_cur_open'] = '<strong>'; $conf['default']['link_tag_cur_close'] = '</strong>'; $conf['default']['button_tag_prev_open'] = '<a href=":url">'; $conf['default']['button_tag_next_open'] = '<a href=":url">'; $conf['default']['button_tag_open'] = '<a href=":url" style="font-weight:bold">'; $conf['default']['button_tag_close'] = '</a>'; $conf['default']['button_tag_empty_open'] = '<span>'; $conf['default']['button_tag_empty_close'] = '</span>'; $conf['default']['point_tag_open'] = '<span>'; $conf['default']['point_tag_close'] = '</span>'; /** * 分页样式2 */ $conf['example']['per_page'] = 25; //每个页面中希望展示的项目数量 $conf['example']['num_links_show'] = 9; //数字链接显示数量 $conf['example']['num_point_start_end'] = 2; //“点”前边和后边的链接数量 /** * 是否显示上一页,下一页... */ $conf['example']['show_first'] = true; $conf['example']['show_prev'] = true; $conf['example']['show_next'] = true; $conf['example']['show_last'] = true; $conf['example']['show_goto'] = false; $conf['example']['show_info'] = false; $conf['example']['show_point'] = true; $conf['example']['show_empty_button'] = false; /** * 上一页,下一页...的显示文字内容 */ $conf['example']['first_text'] = 'First'; $conf['example']['prev_text'] = 'Prev'; $conf['example']['next_text'] = 'Next'; $conf['example']['last_text'] = 'Last'; $conf['example']['point_text'] = '...'; /** * 生成html代码部分, :url表示生成链接 */ $conf['example']['full_tag_open'] = '<div class="pages">'; $conf['example']['full_tag_close'] = '</div>'; $conf['example']['num_tag_open'] = ''; $conf['example']['num_tag_close'] = ''; $conf['example']['link_tag_open'] = '<a href=":url">'; $conf['example']['link_tag_close'] = '</a>'; $conf['example']['link_tag_cur_open'] = '<strong>'; $conf['example']['link_tag_cur_close'] = '</strong>'; $conf['example']['button_tag_prev_open'] = '<a href=":url">'; $conf['example']['button_tag_next_open'] = '<a href=":url">'; $conf['example']['button_tag_open'] = '<a href=":url" style="font-weight:bold">'; $conf['example']['button_tag_close'] = '</a>'; $conf['example']['button_tag_empty_open'] = '<span>'; $conf['example']['button_tag_empty_close'] = '</span>'; $conf['example']['point_tag_open'] = '<span>'; $conf['example']['point_tag_close'] = '</span>'; /** * 配置保存在文件中, 生产环境下自动从缓存读取配置, 不需要下一行代码 */ $pagination->configHandle->addConfig($conf); /** * 初始化 */ $pagination->init(); /** * 切换分页样式,如果是调用默认分页样式,这句可以不加 */ $pagination->setPager('example'); /** * 显示第一页, 共1000条, * 每页显示多少条使用配置文件, * url中:page表示当前页 */ $pager = $pagination->pager(1, 1000, '?page=:page'); $this->assertEquals($pager, '<div class="pages"><strong>1</strong><a href="?page=2">2</a><a href="?page=3">3</a><a href="?page=4">4</a><a href="?page=5">5</a><a href="?page=6">6</a><a href="?page=7">7</a><a href="?page=8">8</a><a href="?page=9">9</a><span>...</span><a href="?page=39">39</a><a href="?page=40">40</a><a href="?page=2" style="font-weight:bold">Next</a><a href="?page=40" style="font-weight:bold">Last</a></div>'); }
$conf['pagination.pager']['full_tag_close'] = '</div>'; $conf['pagination.pager']['num_tag_open'] = '<ul class="pages">'; $conf['pagination.pager']['num_tag_close'] = '</ul>'; $conf['pagination.pager']['link_tag_open'] = '<li class="page-number"><a href=":url">'; $conf['pagination.pager']['link_tag_close'] = '</a></li>'; $conf['pagination.pager']['link_tag_cur_open'] = '<li class="page-number pgCurrent">'; $conf['pagination.pager']['link_tag_cur_close'] = '</li>'; $conf['pagination.pager']['button_tag_open'] = '<li class="pgNext"><a href=":url">'; $conf['pagination.pager']['button_tag_close'] = '</a></li>'; $conf['pagination.pager']['button_tag_empty_open'] = '<li class="pgNext pgEmpty">'; $conf['pagination.pager']['button_tag_empty_close'] = '</li>'; $conf['pagination.pager']['point_tag_open'] = '<li>'; $conf['pagination.pager']['point_tag_close'] = '</li>'; $pagination = new LtPagination(); $pagination->configHandle->addConfig($conf); $pagination->init(); $pager = $pagination->pager($page, 1000, '?page=:page'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Pagination</title> <style type="text/css"> a:link { color:#000; text-decoration:none; } a:visited { color:#000; text-decoration:none; } a:active, a:hover { text-decoration:none; } #pager ul.pages { display:block; border:none; text-transform:uppercase; font-size:10px; margin:10px 0 50px; padding:0; } #pager ul.pages li { list-style:none; float:left; border:1px solid #ccc; text-decoration:none; margin:0 5px 0 0; padding:5px; } #pager ul.pages li:hover { border:1px solid #003f7e; } #pager ul.pages li.pgEmpty { border:1px solid #eee; color:#eee; }