CodeIgniter Pagination Demo:

This is a small example demo application based on codeigniter pagination tutorial. You can checkout how the pagination would work on your real time application. Currently few example data are added and are paginated. However, you can add as many data you want using the codeigniter contact demo page. Also, please refer to the complete code below the example to see how this is working behind the scene.

View The Codeigniter Pagination Tutorial


Contact Messages Listings:

Id Name Email Subject Message Sent
271 Tina Tina@BestFacebookBusinessPages.net ...have you seen this Facebook page?? GoodMorning, Aug 14th. Gorgeous day out there. And it just got a LOT... Aug 14, 2019
272 Brenna BrennaWilpon@TopFaceBookPages.com ...one amazing FB page that you need to know about... Well hi! If you want to discover the best Facbook pages out there on a... Aug 16, 2019
273 Verline Chhun verline@perfectmedialab.com Invest In The Channel Generating The Highest ROI - Risk-Free For 60 Days Invest In The Channel Generating The Highest ROI - Risk-Free For 60 Days... Aug 30, 2019


The Controller Code:

   
    public function pagination_demo($page=1){
        $this->load->model("messagemodel");
        $this->load->library('pagination');
        $this->load->library('app/paginationlib');
        $this->load->language("message");
        try
        {
            $pagingConfig   = $this->paginationlib->initPagination("/codeigniter/pagination-demo",$this->messagemodel->get_count());
            
            $this->data["pagination_helper"]   = $this->pagination;
            $this->data["messages"] = $this->messagemodel->get_by_range((($page-1) * $pagingConfig['per_page']),$pagingConfig['per_page']);
            
            return $this->view();             
        }
        catch (Exception $err)
        {
            log_message("error", $err->getMessage());
            return show_error($err->getMessage());
        }
    }
       

The Library Code:

   
    /**
     *Initialize the pagination rules for cities page 
     * @return Pagination
     */
class Paginationlib {
    //put your code here
    function __construct() {
         $this->ci =& get_instance();
    }

    public function initPagination($base_url,$total_rows){
        $config['per_page']          = 1;
        $config['uri_segment']       = 3;
        $config['base_url']          = base_url().$base_url;
        $config['total_rows']        = $total_rows;
        $config['use_page_numbers']  = TRUE;
        
        $config['first_tag_open'] = $config['last_tag_open']= $config['next_tag_open']= $config['prev_tag_open'] = $config['num_tag_open'] = '
  • '; $config['first_tag_close'] = $config['last_tag_close']= $config['next_tag_close']= $config['prev_tag_close'] = $config['num_tag_close'] = '
  • '; $config['cur_tag_open'] = "
  • "; $config['cur_tag_close'] = "
  • "; $this->ci->pagination->initialize($config); return $config; } }

    The View Code:

       
        <form action="{$base_url}admin/message/delete" method="POST">
        <table cellspacing="0" cellpadding="4" border="0" class="table">
            <thead>
                <tr>
                    <th> <input type="checkbox" value=""/> </th>
                    <th> Id </th>
                    <th> Name </th>
                    <th> Email </th>
                    <th> Subject </th>
                    <th> Message </th>
                    <th> Sent </th>
                </tr>
            </thead>
            <tbody>
    
                {foreach from=$messages item=message name="outer"}
                    <tr>
                        <td> <input type="checkbox" name="id[]" value="{$message->getId()}"/> </td>
                        <td> {$message->getId()} </td>
                        <td> {$message->getName()} </td>
                        <td> {$message->getEmail()} </td>
                        <td> {$message->getSubject()} </td>
                        <td> {$message->getMessage()|truncate:80} </td>
                        <td> {$message->getTime()|date_format} </td>
                    </tr>
                {/foreach}
    
            </tbody>
        </table>      
        <br />
        <div class="clear pagination">
            <ul>
                {$pagination_helper->create_links()}
            </ul>    
        </div>
        </form>