PHP
  Home arrow PHP arrow Page 4 - Completing a Blogging Application with the Code Igniter PHP Framework
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

Completing a Blogging Application with the Code Igniter PHP Framework
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2009-01-13


    Table of Contents:
  • Completing a Blogging Application with the Code Igniter PHP Framework
  • The full source code of the blogger in its previous state
  • Adding CSS styles to the blogs_comments_view.php file
  • Showing the blogging application’s full source code

  • 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


    Completing a Blogging Application with the Code Igniter PHP Framework - Showing the blogging application’s full source code
    ( Page 4 of 4 )

    As I mentioned in the section that you just read, below I listed the complete source code of this blog application, so you can play around with it and introduce your own improvements. Here it is:


    // 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 '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']);

    }

    }



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

    <style type="text/css">

    body{

    margin: 0;

    padding: 0;

    background: #fff;

    }

    h1{

    font: bold 16pt Arial, Helvetica, sans-serif;

    color: #003399;

    margin: 18px 0 18px 0;

    text-align: center;

    }

    h2{

    font: bold 12pt Arial, Helvetica, sans-serif;

    color: #333;

    margin: 0 0 18px 0;

    }

    p{

    font: normal 11px Verdana, Arial, Helvetica, sans-serif;

    color: #333;

    margin: 0 0 18px 0;

    }

    #container{

    width: 500px;

    background: #ccf;

    padding: 15px;

    margin-left: auto;

    margin-right: auto;

    margin-bottom: 18px;

    }

    #paginglinks{

    width: 500px;

    background: #eee;

    padding: 5px 15px 5px 15px;

    margin-left: auto;

    margin-right: auto;

    }

    a:link,a:visited{

    font: normal 11px Verdana, Arial, Helvetica, sans-serif;

    color: #00f;

    text-decoration: none;

    }

    a:hover{

    color: #f90;

    }

    </style>

    </head>

    <body>

    <h1><?php echo $title;?></h1>

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

    <div id="container">

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

    </div>

    <?php endforeach;?>

    <?php echo $links;?>

    </body>

    </html>



    // definition for 'blogs_comment_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>

    <style type="text/css">

    body{

    margin: 0;

    padding: 0;

    background: #fff;

    }

    h1{

    font: bold 16pt Arial, Helvetica, sans-serif;

    color: #003399;

    margin: 18px 0 18px 0;

    text-align: center;

    }

    h2{

    font: bold 12pt Arial, Helvetica, sans-serif;

    color: #333;

    margin: 0 0 18px 0;

    }

    p{

    font: normal 11px Verdana, Arial, Helvetica, sans-serif;

    color: #333;

    margin: 0 0 18px 0;

    }

    #container{

    width: 500px;

    background: #ccf;

    padding: 15px;

    margin-left: auto;

    margin-right: auto;

    margin-bottom: 18px;

    }

    a:link,a:visited{

    font: normal 11px Verdana, Arial, Helvetica, sans-serif;

    color: #00f;

    text-decoration: none;

    }

    a:hover{

    color: #f90;

    }

    textarea, input.textbox{

    width: 300px;

    padding: 3px;

    font: normal 11px Verdana, Arial, Helvetica, sans-serif;

    color: #000;

    }

    </style>

    </head>

    <body>

    <h1><?php echo $title;?></h1>

    <?php if($result->num_rows()>0):?>

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

    <div id="container">

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

    </div>

    <?php endforeach;?>

    <?php endif;?>

    <div id="container">

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

    </div>

    </body>

    </html>


    Now that you have at your disposal the complete source code of this MySQL-driven blogger, feel free to make your own changes and improvements. This will give you a more solid background in working with Code Igniter. If you’re like me, then you have a lot of fun ahead!

    Final thoughts

    Sad but true, we’ve come to the end of this series. Hopefully, after reading its tutorials, you’ll have a clear idea of how simple it is to build a database-driven application with Code Igniter.

    Of course, a framework like this may not fit all of your needs, particularly when it comes to developing large-scale web programs. If you create small and middle-sized web sites frequently, however, Code Igniter is, in my opinion, one of the best frameworks available today.

    I'll see you in the next PHP development tutorial!



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