The pagination does not match the page numbers displayed. Codeigniter

My controller function

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;

    $data['follow'] = $this->activity_model->get($per_page, $start_from);

   $this->pagination->initialize($config); 

   $data['pagination'] = $this->pagination->create_links();

    $this->load->view('front_end/test' ,$data);
}

my route:

 $route['test'] = "user_activity/test";
 $route['test/(:any)'] = "user_activity/test/$1";

model:

 function get($limit,$start_from)
 {
 $sql = "SELECT * FROM user_follow LIMIT $start_from, $limit";

  $query = $this->db->query($sql);
  return $query->result_array();
 }

The problem is that I have pagination 1,2,3,4,5 .... and on each page I show 3 elements. I want to do this in the url to show my page numbers 1,2,3,4,5

When I click the second page, I show 3. When I click the third page of the show 6 url, etc. +3

Is it possible I spend hours searching for tips on the Internet, but nothing, as I understand it [code] $ config ['use_page_numbers'] = TRUE; [/ code] does what I need, but in my case it still doesn't work,

Maybe you can recommend any library?

+5
source share
3 answers

Pagination (/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;
} 

NEW:

else if-statement, , : 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 ( 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:

.

$i = $uri_page_number - 1; 

OLD ( 230):

if ($this->cur_page == $loop) 

NEW:

URI, , .

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;
}

NEW:

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); 

NEW:

.

$i = $num_pages; 

. , .

, :)

EDIT:

:

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);
}

$start, $per_page * ($start_from-1). $start .

, ( -1). , 10, $start = 10 *(2-1), 10, , 10,20,

, :)

+7

. - , . , CI, . .

, $config['use_page_numbers'] = TRUE , . , , , :    url, , , 2 1, "prev", , .

:

$config['base_url'] = base_url('my/url/page');
$config['total_rows'] = count($this->my_model->get_all());
$config['per_page'] = 2;
$config['use_page_numbers'] = TRUE;     
$config['uri_segment'] = 4; 

//i'm looading the pagination in the constuctor so just init here
$this->pagination->initialize($config); 

if($this->uri->segment(4) > 0)
    $offset = ($this->uri->segment(4) + 0)*$config['per_page'] - $config['per_page'];
else
    $offset = $this->uri->segment(4);
//you should modify the method in the model to accept limit and offset or make another function - your choice       
$data['my_data'] = $this->my_model->get_all($config['per_page'], $offset);


page = false (my/url) (my/url/page) - , 4- uri - false,
page = 0 (my/url/page/0),

page = 1 (my/url/page/1)

, . , , - (my/url/page/2323), , , , - . , .

+11

php, - URL-:

, my/url/page/786 786, php. , :

if (isset($result)) {
  $isArray = is_array($result) ? "YES" : "NO"; //check that result is an array or not as per your requirement.
  if ($isArray == "YES") {
   echo "show your stuffs here..";
  }
  else{
   echo "display your message instead for php error here..";
  }
}

, ... tweet me twitter @sufiyantech

0

All Articles