我设置了 CodeIgniter 分页的属性,但出现错误。
1 2 3 4 5 >
我的分页在第 2-5 页上工作,除了第 1 页。我不知道为什么会这样。这是我的控制器功能,其中控制器名称为c_forum
.
function show_posts_by_chapter($id_chapter=false) {
if($id_chapter==false)
show_404();
$config = array();
$config["base_url"] = base_url() . "index.php/c_forum/show_posts_by_chapter/" . $id_chapter.'/';
$config['total_rows'] = $this->m_forum->num_rows_by_chapter($id_chapter);
$config['per_page'] = 2;
$configp['uri_segment'] = 4;
$choice = $config["total_rows"] / $config["per_page"];
$config["num_links"] = round($choice);
$this->pagination->initialize($config);
$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
$data['chapter_id'] = $id_chapter;
$data['allowed'] = $this->_get_level();
$data['count_rows'] = $config['total_rows'];
$data['posts_all'] = $this->m_forum->get_posts_by_chapter($config['per_page'], $page, $id_chapter);
$data['links'] = $this->pagination->create_links();
$this->load->view('forum/show_posts', $data);
}
视图很简单:
`<?php echo $links; ?>`
得到了答案:我用过$configp['uri_segment'] = 4;
,应该是$config['uri_segment'] = 4;