Inserting Database Records with a CodeIgniter PHP Framework Model
(Page 1 of 4 )
Welcome to the fourth part of an eight-part series that shows you how to build a generic model for the CodeIgniter PHP framework. In this part of the series, I code a new method for the generic model class which allows you to insert new records into the specified database table, as well as update an existing one. Keep reading for the full details.
It’s not surprising that the CodeIgniter PHP framework has a large community of users. It comes packaged with a number of valuable features that make it appealing to many web developers: excellent online documentation (quite possibly its strongest point) and a flat learning curve, a solid set of classes and helpers, and finally, it allows developers to create web applications by using the Model-View-Controller pattern.
However, there’s one feature lacking in CodeIgniter that's a detriment to its unquestionable quality. At the time of writing this article, it doesn’t provide a native ORM model. Of course, this issue can be easily fixed by picking up well-trusted third-party libraries like Simon Stensi’s DataMapper or IgniterRecord, since both of them come equipped with enough functionality to handle not only basic CRUD operations, but the most common types of relations between database tables (one-to-one, one-to-many, many-to-many, etc.).
Even so, it’s also possible to develop a customized generic model for CI that permits you to quickly build PHP applications in a truly painless fashion. That's tje goal of this series of articles. So, if you’re interested in learning how to accomplish this in a few simple steps, then don’t hesitate anymore; begin reading now!
Naturally, if you already went through the previous articles, it’s probable that at this time you have an approximate idea of how to create a generic model for CodeIgniter. And I’m saying this simply because in the earlier tutorials, not only did I create the bare bones structure of this model, but I provided it with some basic functionality, including the ability for fetching records from a specified database table according to certain conditions.
Nonetheless, this generic model needs to be enhanced even more. Thus, with that premise in mind, in this fourth chapter of the series, I’m going to add another method to it, which will be responsible for inserting new records into the associated database table, thus extending its current functionality.
So, are you ready to learn how this whole new method for the generic model of CodeIgniter will be coded? Then let’s get started!