|
本帖最后由 eyouy 于 2017-7-16 18:03 编辑
我的目录结构是这么设置的?
列表页首页:http://www.234.com/news/page/2,3,4,这是列表页首页的格式,
列表目录页:http://www.234.com/news/目录名/page/2,3,4后面2,3,4是分页数字。
现在列表页首页是正常的,但是列表页的目录页,一直显示404,route.php里面设置如下:
PHP复制代码
$route['news/([a-z]+)/page'] = 'news/$1/';
$route['news/([a-z]+)/page/(:num)'] = 'news/$1';
复制代码
route.php里面的正则是目录,如下:
http://www.234.com/news/product/page/ 目录列表首页
http://www.234.com/news/product/page/2 目录列表分页
news里面调用分页的地方
PHP复制代码
//分页
$total_rows = $this->news_model->get_news_nums($dir_path);//总条数
$per_page = 3;//每页显示数量
$offset = intval($this->uri->segment(4));
$data['page'] = $this->page($total_rows,$per_page);
复制代码
$dir_path取的是url中的目录名
PHP复制代码 public function page($total_rows,$per_page)
{
$this->load->library('pagination');
$dir_path = $this->uri->segment(2,0);
if($dir_path == 'page'){
$config['base_url'] = base_url().'news/page/';
}else{
//$config['uri_segment'] = 4;
$config['base_url'] = base_url().'news/'.$dir_path.'/page/';
//$config['base_url'] = site_url('news/'.$dir_path.'/page/');
}
//$dir_path ? $config['base_url'] = base_url().'news'.$dir_path.'page/' : $config['base_url'] = base_url().'news/page/';
//$config['base_url'] = uri_string().'/page/';
$config['total_rows'] = $total_rows;//总数据条数
$config['per_page'] = $per_page;//每页显示数量
$config['num_links'] = 5;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
//第一个链接
$config['first_link'] = '首页';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
//上一页
$config['prev_link'] = '上一页';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
//当前页链接
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
//数字链接
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
//下一页
$config['next_link'] = '下一页';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
//最后一个链接
$config['last_link'] = '尾页';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['reuse_query_string'] = FALSE;
$config['enable_query_strings'] =TRUE;
$config['use_page_numbers'] = TRUE;//默认分页的 URL 中显示的是你当前正在从哪条记录开始分页,如果你希望显示实际的页数,将该参数设置为 TRUE 。
$this->pagination->initialize($config);
$page_list = $this->pagination->create_links();
return $page_list;
} 复制代码
|
|