一、效果图
二、代码
public function articlePage() { $cat_id = $this->input->get("catid"); $search = $this->input->get("search"); $current_page = intval($this->input->get("per_page")); //获取当前分页页码数 $this->load->library('pagination');//加载分页库 $count = $this->article_model->getArticleCount($cat_id, $search); $config['base_url'] = site_url('home/index/index?catid='.$cat_id.'&search='.$search); $config['total_rows'] = $count; $config['per_page'] = 2; $config['num_links'] = 3; $config['first_link'] = '首页'; $config['prev_link'] = '上一页'; $config['next_link'] = '下一页'; $config['last_link'] = '末页'; $config['full_tag_open'] = '<ul class="">'; $config['full_tag_close'] = '</ul>'; $config['first_tag_open'] = '<li>'; $config['first_tag_close'] = '</li>'; $config['prev_tag_open'] = '<li>'; $config['prev_tag_close'] = '</li>'; $config['next_tag_open'] = '<li>'; $config['next_tag_close'] = '</li>'; $config['cur_tag_open'] = '<li class="thisclass">'; $config['cur_tag_close'] = '</a></li>'; $config['last_tag_open'] = '<li>'; $config['last_tag_close'] = '</li>'; $config['num_tag_open'] = '<li>'; $config['num_tag_close'] = '</li>'; $config['page_query_string'] = true; $this->pagination->initialize($config); $data['article'] = $this->article_model->getArticleByPage($current_page, $config['per_page'], $cat_id, $search); $data['link'] = $this->pagination->create_links(); return $data; }
如果你想为分页类生成的每个链接添加额外的属性,你可以通过键值对设置 "attributes" 参数:
$config['attributes'] = array('class' => 'myclass');