PHP
  Home arrow PHP arrow Page 3 - Handling Views with CodeIgniter
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

Handling Views with CodeIgniter
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 6
    2009-03-19


    Table of Contents:
  • Handling Views with CodeIgniter
  • Preparing views to be rendered on screen
  • Creating a content view
  • Building a web page controller class

  • 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


    Handling Views with CodeIgniter - Creating a content view
    ( Page 3 of 4 )

    In the previous section, I explained how to build a couple of static views that will be used later on for generating the header and footer parts of a simple web page. However, the only view file that remains undefined is the one tasked with rendering the main area of this page. In this situation, I’m going to populate this area with content from a MySQL table called “users,” which I also used in some other PHP articles published here at the prestigious Developer Shed network.

    As a quick reminder, the structure of this table looked like this:



    Now that you hopefully recalled how this example table was filled with some trivial records, it’s time to build the view file that loops over each of them. Here it is:


    <div id="content">

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

    <?php foreach($users->result() as $user):?>

    <p><strong>First Name: </strong><?php echo $user->firstname;?></p>

    <p><strong>Last Name: </strong><?php echo $user->lastname;?></p>

    <p><strong>Email: </strong><?php echo $user->email;?></p>

    <hr />

    <?php endforeach;?>

    <?php endif;?>

    </div>


    Undoubtedly, the above view should be fairly easy to grasp for you, since all that it does is iterate over each user fetched from the previous MySQL table and display their first and last names, and their email address, on screen. Before I forget, please save this view under the /application/views/ folder of CodeIgniter, so it can be used later on.

    Done? Great. Having created the view file that generates the dynamic section of the sample web page, the next step I’m going to take will consist of defining a simple controller class. As you’ll see in a moment, this controller will be responsible for loading the three views in a sequential fashion, in this way generating the entire web document.

    This procedure will be shown in the upcoming section of this article, so if you wish to learn more, please read the next few lines.



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Adding Ordering and Grouping Clauses to the ...
    - 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...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek