{"id":1500,"date":"2013-10-16T21:42:42","date_gmt":"2013-10-16T19:42:42","guid":{"rendered":"http:\/\/www.extradrm.com\/?p=1500"},"modified":"2013-10-16T22:06:26","modified_gmt":"2013-10-16T20:06:26","slug":"crud-codeigniter-activerecord","status":"publish","type":"post","link":"http:\/\/www.extradrm.com\/?p=1500","title":{"rendered":"CRUD CodeIgniter \/ ActiveRecord"},"content":{"rendered":"<p>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.<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/Active-Record01.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-1502 aligncenter\" alt=\"Active-Record01\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/Active-Record01.jpg\" width=\"391\" height=\"232\" srcset=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/Active-Record01.jpg 391w, http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/Active-Record01-300x178.jpg 300w\" sizes=\"(max-width: 391px) 100vw, 391px\" \/><\/a><\/p>\n<p>The model using Active Record calling<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/Active-Record02.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-1503 aligncenter\" alt=\"Active-Record02\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/Active-Record02.jpg\" width=\"344\" height=\"109\" srcset=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/Active-Record02.jpg 344w, http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/Active-Record02-300x95.jpg 300w\" sizes=\"(max-width: 344px) 100vw, 344px\" \/><\/a><\/p>\n<p>The view rendering what was passed in $data array : here it is $query<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/Active-Record03.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-1501 aligncenter\" alt=\"Active-Record03\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/Active-Record03.jpg\" width=\"687\" height=\"165\" srcset=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/Active-Record03.jpg 687w, http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/Active-Record03-300x72.jpg 300w\" sizes=\"(max-width: 687px) 100vw, 687px\" \/><\/a><\/p>\n<p>Let us examine another more complex CRUD sample using an array to configure tables names in config folder like that :<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/config.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-1507 aligncenter\" alt=\"config\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/config.jpg\" width=\"438\" height=\"76\" srcset=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/config.jpg 438w, http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/config-300x52.jpg 300w\" sizes=\"(max-width: 438px) 100vw, 438px\" \/><\/a><\/p>\n<p>This will permit to write one ACL model for all tables :<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/ACL-functions.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-1508 aligncenter\" alt=\"ACL-functions\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/ACL-functions.jpg\" width=\"296\" height=\"397\" srcset=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/ACL-functions.jpg 296w, http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/ACL-functions-223x300.jpg 223w\" sizes=\"(max-width: 296px) 100vw, 296px\" \/><\/a><\/p>\n<p>A sample of two get functions using the call to config file :<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/get_user_roles.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-1522 aligncenter\" alt=\"get_user_roles\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/get_user_roles.jpg\" width=\"1050\" height=\"130\" srcset=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/get_user_roles.jpg 1050w, http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/get_user_roles-300x37.jpg 300w, http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/get_user_roles-1024x126.jpg 1024w\" sizes=\"(max-width: 1050px) 100vw, 1050px\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/get_all_roles.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-1521 aligncenter\" alt=\"get_all_roles\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/get_all_roles.jpg\" width=\"452\" height=\"60\" srcset=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/get_all_roles.jpg 452w, http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/get_all_roles-300x39.jpg 300w\" sizes=\"(max-width: 452px) 100vw, 452px\" \/><\/a><\/p>\n<p>More simple get and update functions in Models calls could be like below :<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/insert_message.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-1523 aligncenter\" alt=\"insert_message\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/insert_message.jpg\" width=\"427\" height=\"201\" srcset=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/insert_message.jpg 427w, http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/insert_message-300x141.jpg 300w\" sizes=\"(max-width: 427px) 100vw, 427px\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/update_message.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-1524 aligncenter\" alt=\"update_message\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/update_message.jpg\" width=\"493\" height=\"233\" srcset=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/update_message.jpg 493w, http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/update_message-300x141.jpg 300w\" sizes=\"(max-width: 493px) 100vw, 493px\" \/><\/a><\/p>\n<p>Now we can write an insert function in ACL controller like :<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/add_user.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-1509 aligncenter\" alt=\"add_user\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/add_user.jpg\" width=\"892\" height=\"460\" \/><\/a><\/p>\n<hr \/>\n<p>And we can write an edit function with validations rule in ACL controller like 2 parts below :<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/edit_user01.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-1514 aligncenter\" alt=\"edit_user01\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/edit_user01.jpg\" width=\"886\" height=\"361\" srcset=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/edit_user01.jpg 886w, http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/edit_user01-300x122.jpg 300w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/p>\n<p>In this part of else we will write updates if rule validations are true<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/edit_user02.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-1513 aligncenter\" alt=\"edit_user02\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/edit_user02.jpg\" width=\"864\" height=\"262\" srcset=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/edit_user02.jpg 864w, http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/edit_user02-300x90.jpg 300w\" sizes=\"(max-width: 864px) 100vw, 864px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":2841,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,5],"tags":[245],"youtube_video":null,"_links":{"self":[{"href":"http:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/1500"}],"collection":[{"href":"http:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1500"}],"version-history":[{"count":0,"href":"http:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/1500\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/media\/2841"}],"wp:attachment":[{"href":"http:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1500"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}