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.

Active-Record01

The model using Active Record calling

Active-Record02

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

Active-Record03

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

config

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

ACL-functions

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

get_user_roles

get_all_roles

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

insert_message

update_message

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

add_user


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

edit_user01

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

edit_user02

extradrmtech

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...