PHP
  Home arrow PHP arrow Page 4 - Using Code Igniter to Enable Comments in a 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

Using Code Igniter to Enable Comments in a Blog Application
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 3
    2008-12-30


    Table of Contents:
  • Using Code Igniter to Enable Comments in a Blog Application
  • The application so far
  • Inserting comments with a Blogger controller class method
  • Redefining the blogs_comment_view.php 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


    Using Code Igniter to Enable Comments in a Blog Application - Redefining the blogs_comment_view.php file
    ( Page 4 of 4 )

    Coding a simple web form that permit users to post their comments on a particular blog entry is a no-brainer process that only requires you to modify the signature of the "blogs_comments_view.php" file that you saw before.

    In this case, I'm going to use Code Igniter's "form" helper function to dynamically generate the "action" attribute of the form, and also to create a hidden field that permits us to save the ID of the entry being commented.

    If the previous explanation sounds rather confusing to you, then the following code sample should dissipate any possible doubts that you might still have:

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

    <?php echo form_open('blogger/insert_comment');?>

    <?php echo form_hidden('blog_id',$this->uri->segment(3));?>

    <p>Author:</p>

    <p><input type="text" name="author" class="textbox" /></p>

    <p>Enter your comments below:</p>

    <p><textarea name="text" rows="10" cols="20"></textarea></p>

    <p><input type="submit" value="Submit Comment" /></p>

    </form>

    </body>

    </html>


    Here you have it. Now the above view file includes a basic online form that allows users to submit their comments on a particular blog entry. In addition, it's worthwhile to notice that the ID value of each entry is retrieved via the Code Igniter "uri" class, which is loaded automatically by its default controller.

    And finally, here's an additional screen capture that shows how this view file is rendered by the browser, after including into it the previous HTML form:



    Before you proceed to read the conclusion of this article, don't forget to save this modified version of the view to the Code Igniter /system/application/views/ folder, so it can be loaded by the pertaining controller class.

    Assuming that you have saved the file, it's time to test the improved blogger, right? Please point your browser to the following URL:


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


    Now, click on the link that takes you to the comments web page and simply use the online form to start posting new entries. If everything has been set up correctly, then you'll be amazed how sweetly this blogger works.

    Final thoughts

    In this fourth episode of the series, I finished developing this simple blog application using Code Igniter. Logically, there's plenty of room to introduce your own improvements and features to suit your personal needs; due to the program's flexible structure, this should be a fairly painless process.

    In the next part, I'll be polishing the visual presentation of the blogger, since in its current state, it looks pretty primitive. So, now that you know what the upcoming article will be about, you can't 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 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek