CRUD CodeIgniter / ActiveRecord

CodeIgniter uses a modified version of the Active Record Database Pattern. This pattern allows information to be retrieved, inserted, and updated in your database with minimal scripting. In some cases only one or two lines of code are necessary to perform a database action. CodeIgniter does not require that each database table be its own class file. It instead provides a more simplified interface.


The model using Active Record calling


The view rendering what was passed in $data array : here it is $query


Let us examine another more complex CRUD sample using an array to configure tables names in config folder like that :


This will permit to write one ACL model for all tables :


A sample of two get functions using the call to config file :



More simple get and update functions in Models calls could be like below :



Now we can write an insert function in ACL controller like :


And we can write an edit function with validations rule in ACL controller like 2 parts below :


In this part of else we will write updates if rule validations are true



Since 30 years I work on Database Architecture and data migration protocols. I am also a consultant in Web content management solutions and medias protecting solutions. I am experienced web-developer with over 10 years developing PHP/MySQL, C#, VB.Net applications ranging from simple web sites to extensive web-based business applications. Besides my work, I like to work freelance only on some wordpress projects because it is relaxing and delightful CMS for me. When not working, I like to dance salsa and swing and to have fun with my little family.

You may also like...