Fetching Database Rows with a Model for the CodeIgniter PHP Framework
(Page 1 of 4 )
Welcome to the third part of a series that walks you through building a generic model for the CodeIgniter PHP framework. Comprised of seven tutorials, this series shows you in a step-by-step fashion how to create a useful abstract PHP class that will allow you to fetch, insert, update and delete rows in a specified database table very easily by using only a few child models.
If you’re an enthusiast user of CodeIgniter PHP framework and want to learn how to develop a generic model class that lets you perform CRUD operations against your database tables without having to spend endless hours coding multiple and complex models, then look no further. You've come to the right place.
And now that you’ve been introduced to the primary goal of this series, it’s time to refresh the topics that were discussed in the last article. During that specific tutorial, I added a couple of straightforward methods to the initial “AbstractModel” class for storing the data that the model will use for performing insert and update operations, and also for setting the validation rules that will be applied to this data. Indeed, the way that these methods were implemented was pretty simple, so in theory you shouldn’t have major problems understanding how they work.
However, as I expressed in previous tutorials, the generic model class in its current state doesn’t include much functionality. Fortunately, this scenario is about to change. In the next few lines I’m going to incorporate a brand new method into it, which will be responsible for fetching database records according to certain given conditions.
This method will be a huge improvement that will expand the functionality of the “AbstractModel” class, trust me. So, if you’re interested in learning how it will be coded, then don’t waste more time in preliminaries; start reading this third chapter of the series now!