Home arrow PHP arrow Handling Views with CodeIgniter

Handling Views with CodeIgniter

The Code Igniter framework makes it easy for developers to implement a Model-View-Controller design pattern in PHP. This concept can be difficult for newcomers to grasp, so this seven-part series of articles will focus on one aspect of it: views, and the many clever ways you can handle them with Code Igniter. Welcome to the first part.

TABLE OF CONTENTS:
  1. Handling Views with CodeIgniter
  2. Preparing views to be rendered on screen
  3. Creating a content view
  4. Building a web page controller class
By: Alejandro Gervasio
Rating: starstarstarstarstar / 9
March 19, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Introduction

Any PHP developer who has spent a few weeks working with the CodeIgniter framework quickly discovers its many virtues. It has a relatively flat learning curve, and clear, thorough online documentation. Moreover, it lets users  implement the Model-View-Controller design pattern in a fairly strict fashion, and its flexible structure allows the extension of its core functionality via custom libraries, helpers and plug-ins.

Naturally, for seasoned CodeIgniter users, it's a straightforward process to put all of these features to work together. For newcomers though, things tend to be more complicated, particularly when it comes to taking certain theoretical concepts inherent in the MVC schema and putting them into practice.

As soon as an inexperienced user starts developing a simple web application with CodeIgniter, he/she will be confronted with a number of common questions regarding the proper implementation and usage of Models, Controllers and Views. While learning how to work with Models and Controllers can be a challenging task, at least at first, the truth is that generating views seems to be much more approachable.

To clarify this concept a bit further, say that you’re building a web site comprised of a header section, a main area populated with some database contents, and finally a footer. In a case like this, the approach to be followed is pretty simple: on one hand you’d define a model that performs a few CRUD operations on your database, while on the other hand, there would be a controller that uses the model’s methods to fetch database rows, which would finally be embedded into some views to generate the different sections of the site.

In reality, implementing this view-centric method is actually pretty easy to achieve. However, CodeIgniter provides web developers with enough flexibility to handle views in all sort of clever ways. Therefore, in this series of articles I’ll be discussing in detail some common approaches that you can use to generate views, ranging from loading them sequentially, to using more complex methods, such as including views within other views.

Are you ready to learn how to handle views with CodeIgniter? Then let’s begin right now!



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

blog comments powered by Disqus
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 



© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap

Dev Shed Tutorial Topics: