PHP
  Home arrow PHP arrow Page 2 - 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 - Creating a basic blog application with Code Igniter
    ( Page 2 of 4 )

    Before I start showing you how to add record pagination capabilities to the blog application developed in the preceding article of the series, it’d be pretty useful to recall very quickly how its source files looked originally.

    As I mentioned in the introduction, at its initial stage the blogger was comprised basically of two modules, a controller class and a view file. As with each application built with the MVC design pattern, the controller was responsible for implementing the application logic of the blogger, while the view was charged with handling its visual presentation.

    But it’s time to get rid of boring explanations and show the signature of these two source files. Here they are:

    // definition for 'blogger.php' file (located at /system/application/controllers/ folder)


    class Blogger extends Controller{

    function Blogger(){

    // load controller parent

    parent::Controller();

    // load database class and connect to MySQL

    $this->load->database();

    // load helpers

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

    }

    // display all blog entries

    function blogs(){

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

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

    // load 'blogger_view' view

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

    }

    }



    // definition for 'blogs_view.php' file (located at /system/application/views/ folder)


    <!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;?>

    </body>

    </html>


    At this point, the two source files listed above should look pretty familiar to you. As you’ll surely recall, the first one is the blog controller class, tasked with fetching a group of blog entries stored on a “blogs” MySQL table, and then with embedding them into the corresponding view file, for being displayed on the browser.

    The view file only contains some simple presentation logic, which comes in useful for iterating and printing on screen the aforementioned blog entries.

    Of course, if you’re like me, then it’s quite probable that at this very moment you’re wondering how to test this blog application. Well, it’s really simple, assuming that Code Igniter has been installed and configured correctly in your machine. Only type the following URL into your browser’s address field:

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

    If all goes fine, then you should get the following output:


    This is the title of the first blog


    This is the content of the first blog. This is the content of the first blog. This is the content of the first blog. This is the content of the first blog.

    View Blog Comments >>



    This is the title of the second blog


    This is the content of the second blog. This is the content of the second blog. This is the content of the second blog. This is the content of the second blog.

    View Blog Comments >>



    This is the title of the third blog


    This is the content of the third blog. This is the content of the third blog. This is the content of the third blog. This is the content of the third blog.

    View Blog Comments >>



    This is the title of the fourth blog


    This is the content of the fourth blog. This is the content of the fourth blog. This is the title of the fourth blog. This is the title of the fourth blog.
    View Blog Comments >>



    This is the title of the fifth blog


    This is the content of the fifth blog. This is the content of the fifth blog. This is the title of the fifth blog. This is the title of the fifth blog. This is the title of the fifth blog.
    View Blog Comments >>



    This is the title of the sixth blog

    This is the content of the sixth blog. This is the content of the sixth blog. This is the content of the sixth blog. This is the title of the sixth blog.
    View Blog Comments >>


    This is the title of the seventh blog

    This is the content of the seventh blog. This is the content of the seventh blog. This is the content of the seventh blog. This is the title of the seventh blog.
    View Blog Comments >>


    This is the title of the eight blog


    This is the content of the eight blog. This is the content of the eight blog. This is the content of the eight blog. This is the title of the eight blog.
    View Blog Comments >>


     

    This is the title of the ninth blog


    This is the content of the ninth blog. This is the content of the ninth blog. This is the content of the ninth blog. This is the title of the ninth blog.

    View Blog Comments >>



    This is the title of the tenth blog


    This is the content of the tenth blog. This is the content of the tenth blog. This is the content of the tenth blog. This is the title of the tenth blog.

    View Blog Comments >>


    It’s really amazing to see how easy it is to build a simple blog application using Code Igniter. However, I don’t want to be stuck in this moment, so it’s time to move on and see how to modify the signature of the controller class that you learned before, to provide it with the ability to paginate all of the blog entries.

    To learn how this feature will be incorporated into the program, click on the link below and read the following section.




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