![](/img/trans.png)
[英]How to set class name to <a> tag in CodeIgniter pagination
[英]How to change the href of <a> tag in CodeIgniter pagination
我需要在CodeIgniter分頁中更改<a>
標記的href。 CodeIgniter的$this->pagination->create_links();
函數創建如下鏈接:
<a href="http://example.com/index.php/admin/view/3">3</a>
但是,我需要所有段末尾的頁碼(3)。 像這樣:
<a href="http://example.com/index.php/admin/view/field/created/3">3</a>
<a href="http://example.com/index.php/admin/view/field/created/order/asc/3">3</a>
我怎樣才能做到這一點?
您需要將URL作為配置變量傳遞:
$config = array('base_url' => site_url('/admin/view/field/created'));
$this->pagination->initialize($config);
$this->pagination->create_links();
有關更多配置的可能性,請參見文檔 。
我也遇到了這個。 最簡單的解決方案? 重新配置您的URL結構,以便分頁始終是第一部分。 為了不弄亂排序字段,只需確保頁面始終以分頁加載,即,第一次加載時在該段中放置0。 除了更改設置以使用查詢字符串外,我認為您無法將分頁段輕松移動到其他地方,我想您可以在配置中執行一些邏輯操作,例如:
if(is_numeric($this->uri->segment(2)
{
$config['uri_segment'] = 2;
} else if (is_numeric($this->uri->segment(3) {
$config['uri_segment'] = 3;
}
但說實話,這可能會變得很丑陋,具體取決於要添加的額外細分數量。
您可以嘗試計算“頁碼”和“基本網址”的uri段,如下所示:
// Parsing the URI into an associative array
$uri = $this->uri->uri_to_assoc(4);
$segments = count($uri);
// Calculate the uri segment and base url
if ($segments > 1) {
$uri_segment = 3 + $segments - 1; // 3 segments "index.php/admin/view/ + SORT_SEGMENTS - PAGE_SEGMENT
array_pop($uri); // Pop the page number
$base_url = site_url('admin/view/'. implode('/', $uri));
} else {
$uri_segment = 4;
$base_url = site_url('admin/view/');
}
// Pagination config
$config['base_url'] = $base_url;
$config['uri_segment'] = $uri_segment;
$config['use_page_numbers'] = TRUE;
$config['total_rows'] = YOUR_CONFIG;
$config['num_links'] = YOUR_CONFIG;
$config['per_page'] = YOUR_CONFIG;
$this->pagination->initialize($config);
$pagination = $this->pagination->create_links();
PD:我是阿根廷人,我的英語能力有點差
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.