2015-04-01 47 views
0

我有一个代码点击分页链接功能正常,但如果我点击一个链接,特定链接不显示为活动链接。 我的代码如下CodeIgniter分页先前和活动链接不工作

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,请帮我相同的代码工作的其他控制器,我觉得我缺少的是如何创建的链接工作,看起来像我,CI无法获得被点击的链接是主动链接,请帮助我解决这个问题。

+0

第一个错误的工作:要装入'$这个 - >负载>帮手( “URL”);'两次。尝试将所有'load()'函数放在最上面。 – CodeGodie 2015-04-01 18:04:59

+0

在你的'base_url'结尾删除尾部正斜杠'/' – CodeGodie 2015-04-01 18:12:04

+0

为什么你的URL中有'page'参数'$ config ['base_url'] =“http:// localhost/b3/index。 php/CategoryPost/viewcategory /“。 $名称。 “/ page /”'? – CodeGodie 2015-04-01 18:37:07

回答

0

使用下面的代码尝试,让我知道什么样的结果你会得到:

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

也,你在哪里使用' $ records'变量? – CodeGodie 2015-04-02 15:27:27

+0

我现在已经将其移除,我正在分享链接,您可以在其中查看https://youtu.be/G6p7jm08uMk的工作方式以及共享模型。 – 2015-04-03 18:44:10

+0

请查看模型和控制器的github url https://github.com/Sanjay007/Blog,请让我知道它是否有帮助。 – 2015-04-03 18:57:04

2

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

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

谢谢Shaiful,它的工作:),但你能告诉我它有什么用途,为什么它没有考虑? – 2015-04-03 19:15:47

+0

CI分页尝试检测你当前的页码是什么,哪个分段是页码.'uri_segment'告诉你的页码包含哪个段。如果你不告诉CI尝试自动检测哪一段实际上是段3。在你的情况下,段3不包含页码,所以CI无法检测到页码。希望你明白我的意思 – 2015-04-04 18:44:57

+0

感谢您的信息,我不知道它。谢谢再次 – 2015-04-07 12:46:37

-2
$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