How to create pagination with 3 arguments in url using codeigniter?

I am using Codeigniter 2.2 and I am trying to build pagination, consult the Codeigniter manual and it works great for me when I used as below url

$pages_num: is the amount of pages for view.
http://localhost/Codeigniter2.1.4/public_html/page/$pages_num

      

But I am getting error when I add one argument for url as below code, I am trying to find it 3 weeks ago. But I have no solution. Notes: number 2 is the id categories and number 4 is the number of images in folders

http://localhost/Codeigniter2.1.4/public_html/cat/2/4

      

Here is my code in the controller

$this->load->model('frontend/categories_m');
        $count = $this->db->count_all_results('job');

            $perpage = 2;
        if ($count > $perpage) {
            $this->load->library('pagination');
            $config['base_url'] = site_url('cat/2');
            $config['total_rows'] = $count;
            $config['per_page'] = $perpage;
            $config['uri_segment'] = 3;
            $this->pagination->initialize($config);
            $this->data['pagination'] = $this->pagination->create_links();
            $offset = $this->uri->segment(3);
        } else {
            $this->data['pagination'] = '';
            $offset = 0;
        }
        $this->db->limit($perpage, $offset);

        $this->data['job_cat'] = $this->job_m->get_job();
        $this->data['subview'] = 'cat';
        $this->load->view('_main_layout', $this->data);

      

Here's to view:

 <?PHP if ($pagination): ?>
 <section class="pagination">
 <?PHP echo $pagination; ?>
 </section>
 <?PHP endif; ?>

      

Please, help

Sorry, I cannot post images here

+3


source to share


1 answer


With pagination with codeigniter the default link structure is below

http://website/pages/getPagesViaAjax/3/5

      

Here pages is the controller, getPagesViaAjax is the function inside it, and 3 is the parameter for the category id, and 5 is the number of paged images (i.e. offset)



in this case my pagination config is something like

$config['base_url'] = site_url('getPagesViaAjax/3');
$offset = $this->uri->segment(4);

      

So in this case your offset will be the last argument and i.e. 5 (available in segment 4). So before running your model request, please check the offset.

+1


source







All Articles