HomePHP Working with the Active Record Class in Code Igniter
Working with the Active Record Class in Code Igniter
If you’re a PHP developer who’s searching for a third-party framework that lets you build full-blown web applications without having to deal with a long and hard learning curve, then this group of articles might be what you really need. Welcome to the sixth installment of the series entitled “Introducing the Code Igniter PHP Framework.” By using a hands-on approach, this series of articles walks you through the main features that come packaged with this friendly yet powerful development software that lets you quickly build robust PHP applications.
Naturally, if you’ve already read all the tutorials that precede this one, then you're probably familiar with utilizing some core classes that come bundled with Code Igniter. This framework can be used to perform all sorts of clever tasks, including the validation of HTML forms, working with MySQL, paging database records, and so forth.
Indeed, this PHP 4-based framework allows you to develop a wide range of programs, by using the model imposed by the Model-View-Controller pattern. This pattern makes it extremely convenient to separate application logic from visual presentation.
And now that I mentioned the MVC approach, surely you’ll recall that in the previous article of this series, I explained how to apply this design pattern to developing a web application whose main goal was validating the data entered into a sample online form.
As with any other web program developed with Code Igniter, this data validation application was composed of two primary modules. The first one was a controller class, which implemented all the logic required for checking the validity of the data entered on the mentioned HTML form.
The second module was comprised of two view files, which were used either to redisplay the form in question along with a bunch of error messages, or to print on screen a simple confirmation message, depending on the result of the validation process. Does all of this ring any bells for you? I bet it does!
Besides, as I mentioned earlier, Code Igniter comes equipped with a handy active record class that permits you to select, insert, update and delete database rows without having to explicitly code any SQL statements. Therefore, in the next few lines I’ll be creating some hands-on examples for you, aimed at demonstrating how to use this class to manipulate a few basic records stored on a MySQL table.
Are you ready to learn how to use the active record pattern within the Code Igniter’s context? Then let’s begin now!