Vishal Panara
Vishal Panara

Reputation: 243

codeigniter pagination not wotking

I spend so many time to resolve it, But the issue is the same, I need pagination in my application, I already loaded the pagination library, I dont able to understand what is the issue, Below is my code.

Controller

public function index($offset=0)
{

    $cnt=count($this->model->getDatamodel('item_cat_master'));
    $this->load->library('pagination');
    $config['base_url'] = base_url().'item/itemcat';
    $config['total_rows'] = $cnt;
    $config['per_page'] = 4; 
    $this->pagination->initialize($config); 
    $data['view'] = $this->model->get_my_data('item_cat_master', $config['per_page'], $offset);
    $this->load->view('header');
    $this->load->view('menu');
    $this->load->view('item/item_cat', $data);
    $this->load->view('footer');


}

Model

public function getDatamodel($table)
{
$query=$this->db->get($table);
return $query->result_array();
}

Public function get_my_data($table, $limit, $offset) 
{
$query = $this->db->get($table, $limit, $offset);
return $query->result_array();
}

View

<div class="row">
                    <div class="col-md-12">
                        <!-- start:dynamic data table -->
                        <div class="adv-table">
                            <table  class="display table table-striped" id="example">
                                <thead>
                                    <tr>
                                        <th><input id="checkAll" type="checkbox"></th>
                                        <th>Category Name</th>
                                        <th>Category Description</th>
                                        <th>Modidied On</th>
                                        <th>Action</th>
                                    </tr>
                                </thead>
                                <tbody>
                                <?php foreach ($view as $key) { ?>                 
                                    <tr>
                                        <td><input type="checkbox" name="ck[]" value="<?php echo $key["cat_id"]; ?>"></td>
                                        <td><?php echo $key["ic_name"]; ?></td>
                                        <td><?php echo $key["ic_desc"]; ?></td>
                                        <td><?php $mo = $key["modifiedon"]; echo date("d-M-Y , H:i:s", strtotime($mo)); ?></td>
                                        <td>
                                        <?php
                                        $this->load->model('alldata','model'); 
                                        $encrypted_id = $this->model->encryptdata($key['cat_id']); 
                                        ?>
                                        <a href="<?php echo base_url(); ?>item/itemcat/upditemcat/<?php echo $encrypted_id; ?>" class="btn btn-primary btn-xs" data-toggle="tooltip" data-placement="left" title="" data-original-title="Update"><i class="fa fa-pencil"></i></a>    
                                        <!-- <a href="#" class="btn-success btn-xs" title="view"><i class="fa fa-eye" aria-hidden="true"></i> </a> --></td>
                                    </tr>
                                <?php } ?>    


                                </tbody>
                            </table>
                        </div>
                        <!-- end:dynamic data table -->
                    </div>
                </div>
                <?php
                   echo $this->pagination->create_links();
                ?>

What is the Problem in my code? Can anybody guide me in right direction?

enter image description here

in config.php

$config['base_url'] = 'http://localhost/riims';

htaccess

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /riims/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<ifmodule !mod_rewrite.c>
  ErrorDocument 404 /index.php
</ifmodule>

Upvotes: 0

Views: 34

Answers (1)

B. Desai
B. Desai

Reputation: 16436

Your main method is index which will call by default. But when you use pagination you have to add index in url or you have to configure route accordingly. Add index in pagination url then try

public function index($offset=0)
{

    $cnt=count($this->model->getDatamodel('item_cat_master'));
    $this->load->library('pagination');
    $config['base_url'] = base_url().'item/itemcat/index'; //add index at end
    $config['total_rows'] = $cnt;
    $config['per_page'] = 4; 
    $this->pagination->initialize($config); 
    $data['view'] = $this->model->get_my_data('item_cat_master', $config['per_page'], $offset);
    $this->load->view('header');
    $this->load->view('menu');
    $this->load->view('item/item_cat', $data);
    $this->load->view('footer');


}

Upvotes: 2

Related Questions