PHP
  Home arrow PHP arrow Page 4 - Building a Blogger 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

Building a Blogger with the Code Igniter PHP Framework
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 7
    2008-12-10


    Table of Contents:
  • Building a Blogger with the Code Igniter PHP Framework
  • Start building the blogger with two MySQL database tables
  • Building a blog controller class to display blog entries
  • Defining a simple view 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


    Building a Blogger with the Code Igniter PHP Framework - Defining a simple view file
    ( Page 4 of 4 )

    In the previous section, I explained how to build a controller class that was provided with the capacity to display all of the blog entries stored in the "blogs" MySQL table. Of course this operation can't be performed correctly if I don't first create the corresponding view file that actually renders this blog-related data.

    Thus, taking into account this requisite, below I included the signature of this view, 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 foreach($result->result_array() as $blog):?>

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

    <?php endforeach;?>

    </body>

    </html>


    Despite the short signature of the above view file, it actually performs a few useful tasks that are worth examining in detail. As you can see, this file starts displaying all the corresponding blog entries via a "foreach" loop, including their titles and texts, and it finishes its execution by creating dynamically a link that points to a comments section, in this case by using Code Igniter's "url" helper function.

    Naturally, this section hasn't been created yet, and it must be implemented within the previous controller class. However, since this topic will be discussed in forthcoming tutorials of this series, you shouldn't be concerned about it for the moment.

    Now that you have hopefully grasped how the previous view file works, you should save it to the Code Igniter /system/application/views/folder as "blogs_view.php."

    So far, everything looks good, since at this stage I demonstrated how to build a simple blog application, which for the moment is only capable of displaying a group of blog entries stored previously in a MySQL table.

    If you're like me, then you may want to test the application in question. To do this, simply type the following URL into your browser's address field:

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


    If all goes well, you should get the following output on your browser:


    This is the title of the first blog


    This is the content of the first blog. This is the content of the first blog. This is the content of the first blog. This is the content of the first blog.

    View Blog Comments >>



    This is the title of the second blog


    This is the content of the second blog. This is the content of the second blog. This is the content of the second blog. This is the content of the second blog.

    View Blog Comments >>



    This is the title of the third blog


    This is the content of the third blog. This is the content of the third blog. This is the content of the third blog. This is the content of the third blog.

    View Blog Comments >>



    This is the title of the fourth blog


    This is the content of the fourth blog. This is the content of the fourth blog. This is the title of the fourth blog. This is the title of the fourth blog.
    View Blog Comments >>



    This is the title of the fifth blog


    This is the content of the fifth blog. This is the content of the fifth blog. This is the title of the fifth blog. This is the title of the fifth blog. This is the title of the fifth blog.
    View Blog Comments >>



    This is the title of the sixth blog

    This is the content of the sixth blog. This is the content of the sixth blog. This is the content of the sixth blog. This is the title of the sixth blog.
    View Blog Comments >>


    This is the title of the seventh blog

    This is the content of the seventh blog. This is the content of the seventh blog. This is the content of the seventh blog. This is the title of the seventh blog.
    View Blog Comments >>


    This is the title of the eight blog

    This is the content of the eight blog. This is the content of the eight blog. This is the content of the eight blog. This is the title of the eight blog.
    View Blog Comments >>


    This is the title of the ninth blog

    This is the content of the ninth blog. This is the content of the ninth blog. This is the content of the ninth blog. This is the title of the ninth blog.

    View Blog Comments >>



    This is the title of the tenth blog


    This is the content of the tenth blog. This is the content of the tenth blog. This is the content of the tenth blog. This is the title of the tenth blog.

    View Blog Comments >>


    That was pretty satisfactory, wasn't it? As shown above, this initial version of the blogger works fairly well, since it's capable or displaying all the blog entries stored on the aforementioned "blogs" MySQL table. And naturally, this process has been accomplished by using only a controller and a basic view file.

    What else can you ask for? Well, actually there's many more features that need to be added to the blogger, but they'll be incorporated progressively in successive articles of this series. For the moment, study all of the examples coded here, so you can start familiarizing yourself with developing database-driven programs using Code Igniter.

    Final thoughts

    In this first chapter of the series I explained how to build a basic blog application with the Code Igniter PHP framework. As you saw before, this process was pretty straightforward; it only required the creation of a controller class and a view file. That was all.

    In the next part, I'll be showing you how to use the pagination class that comes bundled with Code Igniter, in order to spawn across several pages all of the blog entries shown previously. Don't miss the upcoming article!



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