Codeigniter分页需要解决方案 - 数字链接工作但页面不适当显示

时间:2012-06-20 07:07:09

标签: codeigniter pagination

我在CodeIgniter 2.x中遇到分页问题 这是我在Controller中的代码:

$config['base_url'] = base_url().'crawl/all/'.$file.'/';
$config['total_rows'] = $total;
$config['per_page'] = 10;
$config['num_links'] = 3;
$config['uri_segment'] = 4;
$config['full_tag_open'] = '<ul id="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_tag_open'] = '<li class="next">';
$config['next_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active">';
$config['cur_tag_close'] = '</li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';

$this->pagination->initialize($config);

$data['total'] = $total;
$data['path'] = $this->path.'/'.$file;
$data['file'] = $file;
$data['batch'] = $this->batch->all($file, $config['per_page'], $config['uri_segment']);

我的观点只是:<?php echo $this->pagination->create_links() ?>

页码的链接有效(它们从1移动到2等),但数据无法正确显示。

1 个答案:

答案 0 :(得分:0)

您错过了页面ID,因为当您点击页面时,页面无需作为查询字符串发送,并且必须为配置添加。

示例代码:

$limit = $this->config->item('paging_limit');
$offset = $id * $limit;

$data['rows'] = $this->news_model->get_moreNews($limit, $offset);
$config["image_url"]=$this->config->item("base_url");
$config['base_url'] = base_url().'/news/morenews/';
$config['total_rows'] = $this->db->count_all('news');
$config['per_page'] = $limit;
$config['chapter'] = $this->input->post('chapter');
$config['page'] = $id;

$this->paginationsimple->initialize($config);
$paginator=$this->paginationsimple->create_links();

$data['paginator'] = $paginator;