CodeIgniter 分页以前的和活动的链接不起作用

CodeIgniter pagination Previous and active Links not Working

我有一个代码,点击分页 links 功能正常,但是如果我点击 link,那个特定的 link 不会显示为活动 link . 我的代码如下

function viewcategory($name) {
    $this->load->database();
    $this->load->model('categorypostmod');

    $page = $this->uri->segment(5);
    $this->load->helper("url");
    $this->load->library('table');

    $this->load->model("site_model");
    $this->load->helper('form');
    $this->load->library('pagination');
    $config['base_url'] = "http://localhost/b3/index.php/CategoryPost/viewcategory/" . $name . "/page/";
    $config['per_page'] = 2;
    $config['num_links'] = 5;

    log_message('info', 'count is ' . $this->categorypostmod->getCategorycount($name));

    $config['total_rows'] = $this->categorypostmod->getCategorycount($name);
    $config['full_tag_open'] = '<ul class="pagination">';

    $config['full_tag_close'] = '</ul>';

    $config['use_page_numbers'] = TRUE;

    $config['next_link'] = 'Next';
    $config['next_tag_open'] = '<li class="next page">';
    $config['next_tag_close'] = '</li>';

    $config['prev_link'] = ' Previous';
    $config['prev_tag_open'] = '<li class="prev page">';
    $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 class="page">';
    $config['num_tag_close'] = '</li>';

    $data['query'] = $this->categorypostmod->getCategorypost($name, $config['per_page'], $this->uri->segment(5));
    $records = $this->db->get('post', $config['per_page'], $this->uri->segment(5));
    $this->pagination->initialize($config);

    $this->load->helper("url");
    $this->load->view('script');
    $this->load->view('head');
    $this->load->view('cat_content_list', $data);

    $this->load->view('aside');
    $this->load->view('bottom');
}

控制器名称是 categorypost,请帮助我,因为相同的代码正在其他控制器上工作,我想我错过了如何创建 links 的工作,在我看来 CI 无法获取被点击的 link 是活动的,请帮我解决这个问题。

您错过了 uri_segment 的配置。添加此配置

$config['uri_segment'] = 5;//for you its 5

尝试使用以下代码,让我知道您得到了什么结果:

function viewcategory($name) {
    $this->load->database();

    $this->load->helper("url");
    $this->load->helper('form');

    $this->load->library('table');
    $this->load->library('pagination');

    $this->load->model('categorypostmod');
    $this->load->model("site_model");

    $page = $this->uri->segment(5);
    $categCount = $this->categorypostmod->getCategorycount($name);

    $config['base_url'] = "http://localhost/b3/index.php/CategoryPost/viewcategory/" . $name . "/page/";
    $config['per_page'] = 2;
    $config['num_links'] = 5;

    log_message('info', 'count is ' . $categCount);

    $config['total_rows'] = $categCount;
    $config['full_tag_open'] = '<ul class="pagination">';

    $config['full_tag_close'] = '</ul>';

    $config['use_page_numbers'] = TRUE;

    $config['next_link'] = 'Next';
    $config['next_tag_open'] = '<li class="next page">';
    $config['next_tag_close'] = '</li>';

    $config['prev_link'] = ' Previous';
    $config['prev_tag_open'] = '<li class="prev page">';
    $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 class="page">';
    $config['num_tag_close'] = '</li>';

    $data['query'] = $this->categorypostmod->getCategorypost($name, $config['per_page'], $page);

    $records = $this->db->get('post', $config['per_page'], $page);

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


    $this->load->view('script');
    $this->load->view('head');
    $this->load->view('cat_content_list', $data);

    $this->load->view('aside');
    $this->load->view('bottom');
}
$config['uri_segment'] = 5 /*aca test values ​​( 1 or 2 or 3 or 4 or 5 or 6 or 7)*/

$data['query'] = $this->categorypostmod->getCategorypost($name, $config['per_page'], $this->uri->segment(5/*aca test values ​​( 1 or 2 or 3 or 4 or 5 or 6 or 7)*/) )

用每个值尝试uri (1,2,3,4).

您可以使用数字 1 或 2 或 3 或 4 或 5 或 6。