PHP
  Home arrow PHP arrow Page 4 - 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 - Finishing the sample PHP application with CodeIgniter
    ( Page 4 of 4 )

    In the previous section, I created the three views that will be used for generating independently several section of a web page. Therefore, the last step that I’m going to take will consist of building the layout view, which was called “main_page.php.” Obviously, this particular file is tasked with concatenating the contents of the other views, meaning that its signature will be very simple to code.

    Below you'll see the entire source code corresponding to this layout file. Have a look at it, please:


    <!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>Sample Web Page</title>

    <style type="text/css">

    body{

    padding: 0;

    margin: 0;

    background: #999;

    }

    #container{

    width: 600px;

    margin: 0 auto;

    }

    #header{

    padding: 10px;

    background: #eee;

    }

    #content{

    padding: 10px;

    background: #9cf;

    }

    #footer{

    padding: 10px;

    background: #eee;

    }

    h1{

    font: bold 2em Arial, Helvetica, sans-serif;

    margin: 0 0 18px 0;

    color: #039;

    }

    h2{

    font: bold 1.5em Arial, Helvetica, sans-serif;

    margin: 0 0 18px 0;

    }

    p{

    font: normal .8em Arial, Helvetica, sans-serif;

    margin: 0 0 18px 0;

    }

    </style>

    </head>

    <body>

    <div id="container">

    <?php

    echo $header.$content.$footer;

    ?>

    </div>

    </body>

    </html>


    If you were expecting to see a lengthy view, you might feel a little disappointed. Apart from including a few basic CSS styles, the above layout file contains only one “echo” PHP statement that appends the contents of the other views to generate the header, main area and footer section of the web page. Of course, this isn’t the only approach that can be utilized for building front-ends dynamically with CodeIgniter, but it certainly is a common one.

    Finally, now that you've learned how to handle views in a few clever ways, feel free to tweak all of the code samples developed in this tutorial. Doing this should give you a more solid understanding of how to create web pages with CI. Whatever you do from this point onward, one thing is for sure: fun is already guaranteed!

    Final thoughts

    It’s really hard to believe, but we’ve come to the end of this series. If you’ve been a patient reader and examined in depth all of the code samples included in these tutorials, then by this time should have a clear idea of how to process views with CodeIgniter. As you can see, there is not just one right way to handle views; CI offers several approaches that can be used to suit the requirements of a specific PHP application.

    From my point of view as a web developer, I find returning strings from views a very useful method for building web pages where static and dynamic contents are generated independently, but again, this is only a matter of personal preference.

    See you in the next PHP development tutorial!



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