Home arrow PHP arrow Building a CodeIgniter Custom Library with Method Chaining

Building a CodeIgniter Custom Library with Method Chaining

Welcome to the seventh part of a 12-part series on the technique of method chaining in PHP 5. In this part, I will demonstrate how method chaining can be used to develop some core methods of a custom library for CodeIgniter.

TABLE OF CONTENTS:
  1. Building a CodeIgniter Custom Library with Method Chaining
  2. Defining the CodeIgniter custom library's first methods
  3. Extending the functionality of the AbstractModel class
  4. Fetching, inserting and updating database records
By: Alejandro Gervasio
Rating: starstarstarstarstar / 1
November 11, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

In case you haven’t explored it in depth yet, method chaining is a useful programming methodology that permits you to build highly modular and compact APIs when using the object-oriented paradigm. This isn’t a proprietary feature of a specific programming language; however, it’s possible to implement it with relative ease in PHP 5.

Thus, if you’re a PHP developer who wants to master the basics of creating chainable methods while defining your own classes, then this series of articles might be the material that you’re looking for. In it you’ll find numerous examples that will show you how to apply the method chaining approach to building real-world applications.

Now that you’re well aware of the goal of these tutorials, it’s time to reexamine the topics that were treated in the previous article. In that part of the series I completed the development of a simple, useful MySQL abstraction class that had the ability to perform typical retrieval queries by means of a few basic chainable methods.

Despite the rather simplistic logic implemented by the methods of this class, this particular example hopefully demonstrated how to use chainable methods for building a PHP program that can be used under “real conditions.”

However, as I said at the beginning of this series, my goal here is to illustrate how this approach can be implemented for creating applications that can be used in production environments. So, with that premise in mind, in the next few lines I’m going to show you in a step-by-step fashion how to build a custom library for the popular CodeIgniter framework. The library will allow you to perform the most common database operations without having to create multiple models.

Also, some of the methods that will be implemented within this application will rely partially on the great DataMapper library developed by Simon Stenhouse at http://stensi.com/datamapper, so I’d like to give the corresponding credit to him. Of course, if you need to get a full-featured ORM for CodeIgniter, I recommend you to give the library a try here (http://stensi.com/datamapper/pages/download.html). It’s really worthwhile.

Finally, a word of warning is in order here before you continue reading: the library will be pretty huge, with plenty of modular chainable methods, so I suggest that you arm yourself with patience and willpower to understand how each method is going to work.

Having clarified those points, it’s time to start building this custom library for CodeIgniter by using the functionality provided by method chaining. Let’s do it right now!



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