在分頁類(/system/libraries/Pagination.php)中進行以下更改,以便它使用頁碼而不是偏移量。
OLD(行146-153):
if ($CI->uri->segment($this->uri_segment) != 0)
{
$this->cur_page = $CI->uri->segment($this->uri_segment);
// Prep the current page - no funny business!
$this->cur_page = (int) $this->cur_page;
}
新:
添加「其他」選項的if語句,以確保默認爲;頁= 1
if ($CI->uri->segment($this->uri_segment) != 0)
{
$this->cur_page = $CI->uri->segment($this->uri_segment);
// Prep the current page - no funny business!
$this->cur_page = (int) $this->cur_page;
}
else
{
$this->cur_page = 1;
}
OLD(線175):
$this->cur_page = floor(($this->cur_page/$this->per_page) + 1);
NEW:
只需註釋出該行以便當前頁面服從控制器/ URI。
//$this->cur_page = floor(($this->cur_page/$this->per_page) + 1);
OLD(線206):
$i = $uri_page_number - $this->per_page;
NEW:
前頁應該總是當前頁面由1減去
$i = $uri_page_number - 1;
OLD(線230):
if ($this->cur_page == $loop)
NEW:
的URI缺少分頁應該被認爲第1頁。
if ($this->cur_page == $loop || ($this->cur_page == 1 && $this->cur_page == $loop))
OLD(線238-247):
if ($n == '' && $this->first_url != '')
{
$output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'">'.$loop.'</a>'.$this->num_tag_close;
}
else
{
$n = ($n == '') ? '' : $this->prefix.$n.$this->suffix;
$output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$n.'">'.$loop.'</a>'.$this->num_tag_close;
}
新:
頁面URL應該使用頁碼和不偏移。
if ($n == '' && $this->first_url != '')
{
$output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$loop.'">'.$loop.'</a>'.$this->num_tag_close;
}
else
{
$n = ($n == '') ? '' : $this->prefix.$n.$this->suffix;
$output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$loop.'">'.$loop.'</a>'.$this->num_tag_close;
}
OLD(線256):
$output .= $this->next_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$this->prefix.($this->cur_page * $this->per_page).$this->suffix.'">'.$this->next_link.'</a>'.$this->next_tag_close;
NEW:
下一頁應該總是當前頁面和總和1.
$output .= $this->next_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$this->prefix.($this->cur_page + 1).$this->suffix.'">'.$this->next_link.'</a>'.$this->next_tag_close;
OLD(線262):
$i = (($num_pages * $this->per_page) - $this->per_page);
新:
末頁應該是總頁數。
$i = $num_pages;
用新行替換所有舊行。確保在更改之前進行文件備份。
希望這有助於:)
編輯:
你需要更新你的控制器功能測試,如:
function test($start_from = 0)
{
$this->load->library('pagination');
$data = array();
$per_page = 3;
$total = $this->activity_model->count_by();
$config['base_url'] = base_url() . 'test';
$config['total_rows'] = $total;
$config['per_page'] = $per_page;
$config['uri_segment'] = 2;
$config['num_links'] = 2;
$config['use_page_numbers'] = TRUE;
$start = $per_page * ($start_from-1);
$data['follow'] = $this->activity_model->get($per_page, $start);
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$this->load->view('front_end/test' ,$data);
}
在這裏,我已經添加了一個新的變量$開始是$per_page * ($start_from-1)
。現在將這個$ start作爲參數傳遞給model。
該做的是什麼乘以每頁的項目數與(當前頁號-1)。這意味着,如果每頁您的項目是10
,你是第二頁的$start = 10 *(2-1)
這給10
上。所以,你的結果會從10,20開始,所以一個
希望這有助於:)
將這個去笨2.0.3?無論如何謝謝你! – Viktors 2012-01-28 20:41:59
行號會有一些小的變化。任何方式試一試。我的是一箇舊版本。請讓我知道它是否有效:) – Sabari 2012-01-29 03:07:50
這件事情對你有用嗎? – Sabari 2012-01-29 10:06:46