drzip28288 2015-04-01 17:59
浏览 36
已采纳

CodeIgniter分页上一个和活动链接不起作用

I have a code where clicking on pagination links functions fine , but if i click on a link that particular link is not showing as active link . my code is as follows

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');
}

Controller name is categorypost ,Please help me as the same code is working on other controller , i think i am missing the working of how links are created , looks like to me that CI is unable to get the link that is clicked is an active one , Please Help me onto this .

  • 写回答

3条回答 默认 最新

  • dtnmnw3697 2015-04-02 15:26
    关注

    Try using the following code, let me know what results you get:

    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');
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题