簡體   English   中英

CI類分頁鏈接麻煩

[英]CI class Pagination links trouble

這是我目前擁有的代碼。 PS:我目前正在編輯此文件,嘗試解決此問題,同時等待有人在此解決。 我不太確定為什么會這樣。

分頁:

$character = $this->uri->segment(3);    
        $config['base_url'] = base_url() . 'index.php/Controller/function/'.$character;
        $config['total_rows'] = $this->Model->browse_total_rows();
        $config['per_page'] = 1;
        $config['num_links'] = 10;
        $config['uri_segment'] = 4;
        $this->pagination->initialize($config);
        if(!is_numeric($character)){$data['records'] = $this->Model->get_records_filtered($character,$config['per_page'],$this->uri->segment(4));}
        else{ $data['records'] = $this->Model->get_records($config['per_page'], $this->uri->segment(3));}
        $data['links'] = $this->pagination->create_links();
        $this->load->view('browse', $data);

每當我進入瀏覽頁面時,而不是位於分頁頁面的第1頁上。 默認情況下,第2頁上的im。為什么? 因為我認為這是我的鏈接。

1 2 3>

另外,我不能單擊鏈接2,但可以單擊鏈接1。我不知道這是pagination_links是如何工作的。 但我覺得很奇怪。 無論如何,我不確定它是否與我的其他問題有關。

字符部分用於所選的字母,因此,例如,我只想查看結果以url作為第一個字母A。

index.php/controller/function/A/

因此,每頁的分頁將放置在第4段。 這樣就沒有錯誤。 但是,當我不單擊任何字母並僅顯示所有結果時。

每當我單擊鏈接(每頁)時。 網址看起來像這樣。

index.php/controller/function/2/ 

但是當我點擊下一頁時

 index.php/controller/function/2/4

因此基本上會破壞分頁並且沒有任何結果。

我嘗試了其他解決方案,例如添加IF / else語句,如果字符為null或不等於range('A','Z')$config['base_url']末尾應沒有.$character 。 uri_segment應該在3號。 但它仍然與上述相同。

編輯:

第二個問題解決了,我用了這樣的東西。

$character = $this->uri->segment(3);
$Alphabet = range('A','Z');
$flag = 0;

for($i=0;$i<26;$i++)
{
    if($character==$Alphabet[$i])
    {
        $flag +=1;
    }
} 

好像, if($character==range('A','Z'))正常工作,只是當我回顯該范圍返回數組的結果時才注意到,所以我不得不循環。 有什么比以上我做的更好的檢查方法?

使用分頁配置,無論是否指定字母,都將分頁段設置為4。 但是,如果我理解正確的話,沒有字符時應該為3。

嘗試這樣的事情:

if(!is_numeric($character)) {
    $config['uri_segment'] = 4;
    $data['records'] = $this->Model->get_records_filtered($character,$config['per_page'],$this->uri->segment(4));
} else {
    $config['uri_segment'] = 3;
    $data['records'] = $this->Model->get_records($config['per_page'], $this->uri->segment(3));
}
$this->pagination->initialize($config);

要檢查范圍內的字符,可以使用

if (in_array(strtoupper($character), range('A', 'Z'))

strtoupper()是可選的。 如果您希望“ a”與“ A”匹配,則將其保留。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM