PHP
  Home arrow PHP arrow Page 4 - 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 - Modifying the original view file
    ( Page 4 of 4 )

    Provided that you already grasped how the previous controller class paginates all of the blog entries via the corresponding pagination class, now it’s time to modify the signature of the view file so that it can display the pertinent paginated links too.

    As you saw before, the controller passes to the view a $data array that contains an element referenced as $data[‘links’]. This one is actually the string that renders the paginated links, so in order to display them along with the blog entries, the view should be modified in the following way:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <title><?php echo $title;?></title>

    </head>

    <body>

    <h1><?php echo $title;?></h1>

    <?php foreach($result->result_array() as $blog):?>

    <h2><?php echo $blog['title'];?></h2>

    <p><?php echo $blog['text'];?></p>

    <p><?php echo anchor('blogger/comments/'.$blog['id'],'View Blog Comments &gt;&gt;');?></p>

    <?php endforeach;?>

    <?php echo $links;?>

    </body>

    </html>


    Now, all of the blog entries fetched from the “blogs” MySQL table will be displayed across several pages, along with the paginated links. In addition, you should first save the improved version of this view to the Code Igniter /system/application/views/ folder as “blogs_view.php.”

    Once you’ve done this, type the following URL into your browser’s address field:


    http://localhost/codeigniter/index.php/blogger/blogs/


    If all goes as expected, you should get the below output:


     


    Here you have it! At this point you should feel pretty satisfied, since now the blog application is capable of displaying a group of blog entries which have been paginated. Definitely, that was a neat improvement, right?

    To wrap up this tutorial, I encourage you to tweak all of the code samples I've included here, so you can introduce more improvements to the blog application.

    Final thoughts

    In this second chapter of the series, I demonstrated how to add record pagination capabilities to the blog application built earlier. As you saw for yourself, this process only required using the Code Igniter’s pagination class, and introducing a few simple changes to the controller and the view as well.

    In the upcoming article, I’ll continue adding more features to the blogger, such as the ability to post comments on each blog entry.

    However, to learn how this will be done, you’ll have to read the next part! See you next week.



     
     
    >>> 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 1 Hosted by Hostway
    Stay green...Green IT