PHP
  Home arrow PHP arrow Page 4 - Displaying User Comments in a Code Igniter Blog Application
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? 
Google.com  
PHP

Displaying User Comments in a Code Igniter Blog Application
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 3
    2008-12-23


    Table of Contents:
  • Displaying User Comments in a Code Igniter Blog Application
  • Review: displaying paginated blog entries
  • Displaying user-supplied comments
  • Creating a view file to display user-submitted comments

  • 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


    Displaying User Comments in a Code Igniter Blog Application - Creating a view file to display user-submitted comments
    ( Page 4 of 4 )

    As I stated in the previous section, to finish developing this blog application with Code Igniter, it’s necessary to create another view file. This file will be charged with printing, on screen, all of the comments that have been submitted for each blog entry.

    To demonstrate how this file really functions, I’m going to assume that a few trivial comments have already been stored in the pertinent “blogs_comments” MySQL table. However, in a typical situation, users should be able to post their comments via an HTML form. Since this topic will be covered in depth in the next tutorial of the series, for now I’ll keep the blog application working this way.

    Now that I have explained the functionality of the “blogs_comment_view.php” file, please take some time to study its signature, which looks like this:

    <!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 if($result->num_rows()>0):?>

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

    <p><strong>Author: </strong><?php echo $comment['author'];?></p>

    <p><strong>Comment:</strong></p>

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

    <p><?php echo anchor('blogger/blogs/','&lt;&lt; Back to blog');?></p>

    <?php endforeach;?>

    <?php endif;?>

    </body>

    </html>


    As illustrated above, the previous view file is responsible for performing a few interesting tasks, such as displaying all the comments that have been made on a particular entry, and including a link that takes users to the blogger’s main page.

    In addition, you can see that each comment includes the author that submitted it and the corresponding text as well. Nonetheless, as I stated before, this operation should be performed through a typical web form; the details of this topic will be discussed in the next article in this tutorial series.

    For now, the only step that remains undone is to save the previous view file to the Code Igniter /system/application/views/ folder, so go ahead and do that. Then, if you test the blog application and click on any of the links that points to the comments web page, you should get an output similar to this:



    Naturally, the above image exemplifies a situation where some blog entries have already received comments, so you can see more clearly how the blogger works.

    Okay, at this point, the initial functionality of this blog application has been slightly extended; it's now capable of displaying not only all of the existing blog entries, but the comments that have been posted on each of them. As usual with many of my articles on PHP development, feel free to tweak all the code samples developed in this tutorial to expand your existing Code Igniter skills.

    Final thoughts

    In this third part of the series, I explained how to improve the functionality of this blogger by providing it with the capacity for displaying a bunch of comments that correspond to each blog entry. However, as I explained earlier, for entering new comments it is necessary to code a typical HTML form.

    Therefore, in the following article I’ll discuss how to achieve this with Code Igniter. Now that you know what will be covered in the next tutorial, you don’t have any excuses to miss it!



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

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek