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.

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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

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

}

}



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

<?php echo $links;?>

</body>

</html>


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
   

PHP ARTICLES

- 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: