How to use page numbers in field codes instead of offset?

I read all the questions about Stackoverflow and did not find a definitive answer to the question. I am currently using the code break library to create page links using limit and offset:

$config['base_url'] = base_url() . 'explore/featured/index/';
    $config['total_rows'] = $this->Projects_model->get_featured_count();//Count featured projects
    $config['per_page'] = 12;
    $config['uri_segment'] = 4;
    $config['display_pages'] = FALSE;
    $config['next_link'] = 'Older →';
    $config['prev_link'] = '← Newer';
    $this->pagination->initialize($config);
    $limit = $config['per_page'];
    $offset = $this->uri->segment(4);

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

    $data['projects'] = $this->Projects_model->get_featured($limit, $offset); //get featured projects from database

The above code limits the output of my request and uses the offset contained in my fourth segment of the URI.

How can I change the code below to page numbers ??? It seems impossible, because I can no longer use the offset in my URL.

+5
source share
4 answers

- CI () :

$config['use_page_numbers'] = TRUE;

URI , . , .

, , CI, .

, $limit * $page_number, "page_number" - URL- (4- ).

+16

$limit * $page_number, , , 1, 0 . :

$offset = ($page_number  == 1) ? 0 : ($page_number * $config['per_page']) - $config['per_page'];
+5

Just use:

$offset = ($this->uri->segment(4)) ? $this->uri->segment(4) : 1;
$data['projects'] = $this->Projects_model->get_featured($limit, $limit*($offset-1));
+1
source
$page_num = $this->uri->segment(1);
$offset = ($page_num  == NULL) ? 0 : 
          ($page_num * $config['per_page']) - $config['per_page'];
-1
source

All Articles