PHP
  Home arrow PHP arrow Page 3 - 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 - Inserting comments with a Blogger controller class method
    ( Page 3 of 4 )

    As I expressed in the section that you just read, users will be able to submit several comments on a particular entry by way of a simple web form. As you may guess, this web page element needs to be coded into a view file, since it's a part of the blogger's visual presentation.

    In order to insert these comments into the "blogs_comments" MySQL table, it's necessary to define another method within the controller class that performs this task in a straightforward manner.

    Below I listed the modified version of the controller in question. It incorporates a brand new method called "insert_comment()" that comes in useful for storing user-submitted posts on the corresponding MySQL table. Take a look at it, please:


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

    }

    // insert new blog comment

    function insert_comment(){

    $this->db->insert('blogs_comments',$_POST);

    redirect('blogger/comments/'.$_POST['blog_id']);

    }

    }


    Despite its short signature, the above "insert_comment()" method is indeed quite useful. It inserts a new comment into the "blogs_comments" MySQL table, and then redirects the user to the comments web page when this insertion operation has been accomplished correctly.

    As you can see, comments are collected via a POST HTML form, so in this case the $_POST PHP superglobal array is used for submitting this data to the respective database table.

    Okay, at this stage the "Blogger" controller class has the ability to store new comments about different blog entries on a specific MySQL table. Nevertheless, this process would be rather incomplete if I didn't show you how to code the web form that lets users to accomplish this task in a simple fashion.

    Therefore, in the last section of this article I'll be teaching you how to redefine the signature of the "blogs_comment_view.php" file to include the mentioned online form.

    Please, jump forward and read the following segment.



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