Home arrow PHP arrow Page 2 - Displaying User Comments in a Code Igniter Blog Application

Review: displaying paginated blog entries - PHP

Welcome to the third part of the six-part series titled “Building a Blogger with the Code Igniter PHP Framework.” In successive tutorials, this series shows you how to use this software package to develop a blog application by using the Model-View-Controller design pattern. In this article, you will learn how to make the application display user comments.

  1. Displaying User Comments in a Code Igniter Blog Application
  2. Review: displaying paginated blog entries
  3. Displaying user-supplied comments
  4. Creating a view file to display user-submitted comments
By: Alejandro Gervasio
Rating: starstarstarstarstar / 7
December 23, 2008

print this article



Before I proceed to modify the signature of the controller class that I built in the previous article, I’d like to list it in its current state, along with the corresponding view file. This will remind you of how these two source files looked before we make the appropriate changes to their respective signatures.

That being said, here are the definitions for the files in question:

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

class Blogger extends Controller{

function Blogger(){

// load controller parent


// load database class and connect to MySQL


// load pagination library


// load helper



// display all blog entries

function blogs(){

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


// set pagination parameters




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



// create pagination links


// load 'blogger_view' view




// 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">


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

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



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



As you can see, the above “Blogger” controller class implements a method called “blogs(),” which not only retrieves all the entries from the pertinent “blogs” MySQL table, but splits this data into several chunks. In this way it implements an effective pagination mechanism. 

Finally, the controller loads the view file shown above, which is used to display all of the blog entries on screen, along with the corresponding pagination links.

Okay, at this point you hopefully recalled how the two previous files do their business, right? Therefore, it’s time to see how to modify the signature of the controller class, and provide it with the capacity for displaying all of the  comments submitted by users.

The full details of this process will be discussed in the following section. Thus, click on the link below and keep reading, please.

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: