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.

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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
   

PHP ARTICLES

- 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...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


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

Dev Shed Tutorial Topics: