Home arrow PHP arrow Defining a Model Class for Handling Views with CodeIgniter

Defining a Model Class for Handling Views with CodeIgniter

Welcome to the sixth installment of a seven-part series on handling views with the CodeIgniter PHP framework. This series shows you a few handy approaches that you can implement quickly within your CI-based programs to work with view files in a truly clever way, ranging from loading them sequentially to nesting views within other views.

  1. Defining a Model Class for Handling Views with CodeIgniter
  2. Review: moving presentation logic out of views
  3. Handling database contents with a simple model class
  4. Demonstrating a simple use of the model class
By: Alejandro Gervasio
Rating: starstarstarstarstar / 3
April 23, 2009

print this article



And now that youíre aware of the topics that are covered in this group of articles, itís time to review the concepts discussed in the last tutorial. In that part, I used a practical example to show you how to partially remove presentation logic from a particular view file, and implement it within a simple controller class.

As with many other aspects related to using the Model-View-Controller pattern with CodeIgniter, making views a bit ďdumberĒ has its pros and cons. How successful this approach can be in the end depends strongly on the structure defined for a particular application. Again, itís fair to mention here that CI gives developers enough flexibility to implement the MVC pattern without forcing the use of a specific programming methodology. Indeed, this is one of its most appreciated characteristics.

Now, returning to the previous tutorial, youíll recall that I developed a sample PHP application. It displayed the contents of some database rows which were previously fetched from a ďusersĒ MySQL table. Moreover, these rows were retrieved by using the active record class bundled with CI.

However, itís also possible to define a model that performs all of the database-related operations, instead of directly using the database class. Thus, in the next few lines Iím going to show you how to build another web application similar to the one that you learned in the preceding article -- but this time it will incorporate a basic model class. In doing so, youíll be able to see how to handle views by using the entire Model-View-Controller triad.

Are you ready to continue learning how to parse views with CodeIgniter? Then letís jump right in!

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- 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


Dev Shed Tutorial Topics: