PHP
  Home arrow PHP arrow Page 3 - 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 - Displaying user-supplied comments
    ( Page 3 of 4 )

    To be frank, providing the previous “Blogger” controller class with the capacity for displaying all of the comments that have been made on each blog entry is only a matter of adding to the class a simple method which performs that specific task.

    However, it’s probable that this concept will be easier to understand if you look at the modified signature of the controller class. It includes a brand new method, called “comments(),” tasked with showing all the comments posted for each blog entry. Here it is:

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

    }

    // display all blog comments

    function comments(){

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

    $this->db->where('blog_id',$this->uri->segment(3));

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

    // load 'blogs_comment_view' view

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

    }

    }


    As I mentioned before, the above “Blogger” controller class now includes another method, not surprisingly called “comments().” It is responsible for fetching, from the pertinent “blogs_comments” MySQL table, all of the comments that have been posted about a particular blog entry.

    In order to perform this task, the method executes a WHERE conditional clause against the table using the active record pattern. It's worth noticing, by the way, that there are no SQL statements coded explicitly here.

    And finally, once the corresponding database rows has been retrieved, then they’re embedded into a view file so they can be displayed at a later time. Obviously, if you analyze this process pretty closely, you may now be asking yourself the following question: how can users post their comments on one or more blog entries?

    Well, I‘m glad you asked! As I explained a few lines above, the “comments()” method inserts the data retrieved from the “blogs_comments” MySQL table into a view file called “blogs_comment_view.php,” right? This file will include a simple HTML form which let users submit several comments on different blog entries. Now, are you starting to realize how this method does its thing? I bet you are!

    However, to dissipate any possible doubts that you might have regarding how the “comments()” method works, in the section to come I’ll be listing the signature of the “blogscomments_view.php” file. You'll be able to study it in detail.

    In the meantime, save the modified version of the previous “Blogger” controller class to the Code Igniter /system/application/controllers/ folder as “blogger.php,” then click on the link that appears below and keep reading.



     
     
    >>> 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 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek