PHP
  Home arrow PHP arrow Page 3 - Embedding Model Data in Views with Code Igniter
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

Embedding Model Data in Views with Code Igniter
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2009-04-30


    Table of Contents:
  • Embedding Model Data in Views with Code Igniter
  • Review: the first two modules of the previous web application
  • Creating some basic view files
  • Finishing the sample PHP application with CodeIgniter

  • 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


    Embedding Model Data in Views with Code Igniter - Creating some basic view files
    ( Page 3 of 4 )

    If you already went through the preceding articles of this series, then you're already familiar with building simple views. The views that I plan to build now will be really simple to grasp as well. As you’ll surely recall from the controller defined in the previous section, these views must be capable of generating independently the header, main area and footer section of a web page. This is actually very easy to accomplish. 

    Here are the three views that render the web page in question:


    (‘header_view.php’ file – located at /application/views/ folder)


    <div id="header">

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

    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut.</p>

    </div>



    (‘content_view.php’ file – located at /application/views/ folder)


    <div id="content">

    <?php foreach($users 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;?>

    </div>



    (‘footer_view.php’ file – located at /application/views/ folder)


    <div id="footer">

    <h2><?php echo $footer;?></h2>

    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut.</p>

    </div>  


    As I said before, the signatures corresponding to the above views are fairly simple to understand. In this case, the “content_view.php” file is possibly the most complex to grasp, but all that it does is iterate over all the rows fetched from the pertinent “users” MySQL table and display the users’ first and last names, as well as their email addresses.

    Due to the simple structure of the views coded before, I don’t want to spend more time explaining what they do, since that would be pretty pointless. However, as you may have noticed, there’s still one view that remains undefined, called “main_page.php,” which is precisely the one responsible for concatenating the other views.

    Therefore, the last segment of the tutorial will be focused on creating this layout view, in this manner concluding this instructive journey on handling views with CodeIgniter. Now, if you want to see how this view will be coded, click on the link shown below and read the following section.



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