Search code examples
phpcodeigniterpagination

pagination with codeigniter not generating values


I have been trying to get this done, I want a pagination in my app. what i have now can only count the table rows. but when i click on the link to next batch of data, i receive a error 404.

Here is the code below. This is my Controller

public function index($page='dboard', $offset=0){
        $config['base_url'] = base_url() . 'manager/cplfc/';
        $config['total_rows'] = $this->db->count_all('users','attendance');
        $config['per_page'] = 1;
        $config['uri_segment'] = 1;
        $config['attributes'] = array('class' => 'pagination');

        // Init Pagination
        $this->pagination->initialize($config);


     $data['users'] = $this->ManagerModel->get_users(FALSE, $config['per_page'], $offset);

    if(!file_exists(APPPATH.'views/controls/manager/'.$page.'.php')){show_404();}
    $data['title']=ucfirst($page);
    $this->load->view('controls/manager/header');
    $this->load->view('controls/manager/'.$page,$data);
    $this->load->view('controls/manager/footer');
}

and this is the Model

public function get_users($id = FALSE, $limit = FALSE, $offset = FALSE){
    if($limit){
            $this->db->limit($limit, $offset);
        }
    if($id === FALSE){
        $this ->db->order_by('id', 'desc');
        $query = $this->db->get('users');
        return $query->result_array();
        }
    }

And this is my view

<div class="pagination pagination-centered">
                            <ul><li><?php echo $this->pagination->create_links(); ?></li></ul>
                        </div>

What can i do to make it work? Thanks in advance


Solution

  • All I needed was to set the URL Segment to "4" because the URL

    $config = array();
    $offset = $this->uri->segment(4);
    $config['base_url'] = base_url() . 'manager/cplfc/';
    $config['total_rows'] = $this->db->count_all('users','attendance');
    $config['per_page'] = 1;
    $config['uri_segment'] = 1;
    $config['attributes'] = array('class' => 'pagination');