Validating Input Data with the CodeIgniter PHP Framework
(Page 1 of 4 )
Welcome to the sixth installment of the series that shows you how to build a generic model for the CodeIgniter PHP framework. Made up of eight parts, this series walks you through the development of a simple model class for the CodeIgniter PHP framework. This class will allow you to retrieve, save and delete rows of a specified database table with minor hassles by using a truly straightforward programming interface, along with a few basic child models.
And now that you've been introduced to the main goal of this series of articles, it’s time to review the topics that were covered in the last tutorial, in case you haven’t had the chance to read it yet. In that particular installment I proceeded to implement a new method within the already familiar “AbstractModel” class, called “save().” It came in handy for deleting rows from the model’s associated database table, thus providing the class with the ability to perform basic CRUD operations.
Also, it’s valid to point out that from an average programmer’s point of view, the model class in its current incarnation should quite decently fill the requirements of most database-driven web applications. However, as I explained in previous articles, it’d be truly useful to give the class the capacity to validate input data before inserting and updating database records, thus avoiding the situation where the corresponding controllers replicate this task at several points of a PHP application.
Therefore, in the next few lines I’m going to add another method to the “AbstractModel” class, which will be responsible for validating incoming data prior to performing inserts and updates on the specified database table. Want to learn how this method will be coded using the native resources of CodeIgniter? Then start reading now!
Next: Review: the complete source code of the generic model class >>
More Miscellaneous Code Articles
More By Alejandros Gervasio