PHP
  Home arrow PHP arrow Using Nested 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? 
PHP

Using Nested Views with CodeIgniter
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2009-04-02


    Table of Contents:
  • Using Nested Views with CodeIgniter
  • Review: loading views sequentially with CodeIgniter
  • Preparing a nested view for displaying database contents
  • Embedding actual data into views with 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


    Using Nested Views with CodeIgniter
    ( Page 1 of 4 )

    One of the most common tasks that a PHP programmer has to perform when developing web applications with CodeIgniter is loading a bunch of views to generate different sections of a web document. As with many other features provided by this framework, there are several ways to work with view files. This seven-part article series shows you many different ways to handle views. In this third part, we'll focus on nested views and other methods.

    Introduction

    As I mentioned, there are several ways to work with view files with the CI framework, ranging from loading them sequentially and using the “$this->load()->vars()” method, to including views within other views.

    Of course, it’s also possible to combine all of these approaches to build dynamic web pages, depending on the requirements of a specific PHP program. In this series of articles you’ll find concise code samples that will show you different methods that you can use for loading views within your CI-based applications.

    And now that you've been introduced to the main subject of this series of tutorials, it’s time to refresh the topics that were discussed in the last one, in case you haven’t had opportunity to read it yet. In that article I explained how to improve the visual appearance of a basic web page, which was generated by loading sequentially three different views, where each of them was tasked with building the header, main area and footer section of the page.

    Actually, CodeIgniter is smart enough to concatenate the contents of views, if they’re loaded in a sequential manner from inside a controller or from another view. This makes it much easier to generate web pages like the one mentioned above.

    As I said before, however, there are several methods that can be utilized for loading view files, and in this third chapter of the series I’m going to discuss one that bases its functionality on the loader class that comes bundled with CI. If you’ve already seen the official user guide, then you may know that this class has a useful method called “$this->load->vars()” that behaves similarly to the “extract()” PHP native function.

    By means of this method, it is very simple to replace in one single step all the variables included into multiple views with actual data. Therefore, in the next few lines I’m going to discuss how to use it to generate a dynamic web document, which will display some database contents.

    Now, let’s get rid of the prologue and start discovering how to handle view data with CodeIgniter’s “$this->load->vars()” method. Let’s go!



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

       

    PHP ARTICLES

    - 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
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT