PHP
  Home arrow PHP arrow Page 3 - Paginating Blog Entries with Code Igniter
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Paginating Blog Entries with Code Igniter
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2008-12-17


    Table of Contents:
  • Paginating Blog Entries with Code Igniter
  • Creating a basic blog application with Code Igniter
  • Adding records pagination capabilities
  • Modifying the original view file

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Paginating Blog Entries with Code Igniter - Adding records pagination capabilities
    ( Page 3 of 4 )

    In truth, providing the previous “Blogger” controller with the capacity for paginating blog entries is only a matter of using the pagination class that comes bundled with Code Igniter. It’s that simple, believe me.

    However, it’s necessary to demonstrate how to perform this task with some functional code. Therefore, below I included the improved signature of the controller class, which this time will be capable of paginating all of the blog entries. Have a look at it, please:


    class Blogger extends Controller{

    function Blogger(){

    // load controller parent

    parent::Controller();

    // load database class and connect to MySQL

    $this->load->database();

    // load pagination library

    $this->load->library('pagination');

    // load helper

    $this->load->helper('url');

    }

    // display all blog entries

    function blogs(){

    $data['title']='Blog Entries Listing';

    $data['result']=$this->db->get('blogs',3,$this->uri->segment(3));

    // set pagination parameters

    $config['base_url']='http://127.0.0.1/codeigniter/index.php/blogger/blogs/';

    $config['total_rows']=$this->db->count_all('blogs');

    $config['per_page']='3';

    $config['full_tag_open']='<div id="paginglinks">';

    $config['full_tag_close']='</div>';

    $this->pagination->initialize($config);

    // create pagination links

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

    // load 'blogger_view' view

    $this->load->view('blogs_view',$data);

    }

    }


    As shown above, the controller class now incorporates a few interesting changes that deserve a closer analysis. First, apart from loading the database class and the “url” helper, it includes the pagination class, which not surprisingly is called “pagination.”

    So far, the way that the constructor works is very understandable, isn’t it? Thus, move on and take a close look at the “blogs()” method. As you can see, it fetches chunks of rows from the “blogs” MySQL table, and also assigns some settings to the pagination class, such as the base URL and the number of rows that will be displayed per page, the opening and close tags that will be used for showing the paging links, and so forth.

    Once this class have been configured correctly, the blog entries are embedded into the respective view, along with the paginated links in question, to be displayed later on the browser. Simple and sweet!

    At this point, the controller class has the ability to span the blog entries across several pages. Of course, there are other parameters that you can use to configure the pagination class, but for the moment I’ll use the ones discussed before.

    Now that the controller class has been enhanced, it should be saved to the Code Igniter /system/application/controllers/ folder as “blogger.php” for later use.

    Did you do it? Then it’s time to see how to modify the view file, so it can display the paginated links as well.

    Precisely, this will be the subject that I’m going to discuss in the next section, so go ahead and read the next segment.



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT