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.

  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



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