2015-04-01 74 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