Wprowadź następujące zmiany w klasie stronicowania (/system/libraries/Pagination.php), aby używać numerów stron zamiast przesunięć.
OLD (linie 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;
}
NOWOŚĆ:
Dodaj „inny” opcja if-oświadczenie, aby upewnić się domyślnym jest; page = 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 (linia 175):
$this->cur_page = floor(($this->cur_page/$this->per_page) + 1);
NOWOŚĆ:
prostu skomentuj tę linię tak aktualna strona przestrzega kontroler/URI.
//$this->cur_page = floor(($this->cur_page/$this->per_page) + 1);
OLD (linia 206):
$i = $uri_page_number - $this->per_page;
NOWOŚĆ:
Poprzednia strona powinna być zawsze aktualna strona odejmowane przez 1.
$i = $uri_page_number - 1;
OLD (Linia 230):
if ($this->cur_page == $loop)
NOWOŚĆ:
URI brakuje stronicowania należy uznać strona 1.
if ($this->cur_page == $loop || ($this->cur_page == 1 && $this->cur_page == $loop))
OLD (linia 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;
}
NOWOŚĆ:
Page URL powinny używać numerów stron, a nie przesunięć.
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 (linia 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;
NOWOŚĆ:
Następna strona powinna być zawsze sumą bieżącej strony i 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 (linia 262):
$i = (($num_pages * $this->per_page) - $this->per_page);
NOWOŚĆ:
Ostatnia strona powinna być całkowita liczba stron.
$i = $num_pages;
Zamień wszystkie stare linie na nowe. Przed zmianą upewnij się, że wykonałeś kopię zapasową pliku.
Nadzieja to pomaga :)
EDIT:
Musisz zaktualizować test funkcji kontrolera jak:
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);
}
Tutaj dodałem nową zmienną $ rozpoczęcia który $per_page * ($start_from-1)
. Teraz przekaż ten $ start jako argument do modelu.
Co to jest pomnożyć liczbę elementów na stronie z bieżącym numerem strony (-1) .To znaczy, jeśli pozycji na stronie 10
i jesteś na drugiej stronie $start = 10 *(2-1)
co daje 10
. Więc twój wynik będzie zacząć od 10,20 a więc jeden
Nadzieja to pomaga :)
będzie to idź do CodeIgniter 2.0.3? Mimo wszystko dziękuję ! – Viktors
Pojawią się drobne zmiany w numerach linii. W każdy sposób spróbuj. Mój jest starą wersją. Daj mi znać, czy to działa :) – Sabari
Czy to działa dla Ciebie? – Sabari