{"id":3373,"date":"2013-01-28T00:01:59","date_gmt":"2013-01-28T05:01:59","guid":{"rendered":"http:\/\/ahmeddirie.com\/?p=3373"},"modified":"2015-09-25T05:07:58","modified_gmt":"2015-09-25T12:07:58","slug":"codeigniter-and-the-code-i-didnt-have-to-write","status":"publish","type":"post","link":"https:\/\/ahmeddirie.com\/blog\/web-development\/codeigniter-and-the-code-i-didnt-have-to-write\/","title":{"rendered":"CodeIgniter and the code I didn&#8217;t have to write"},"content":{"rendered":"<p>I finally got around to taking <a href=\"http:\/\/codeigniter.com\" title=\"CodeIgniter\">CodeIgniter<\/a> for a spin and putting it in fifth gear. The amount of code I didn&#8217;t have to write, and the speed at which I was able to pump out a fully working web application is beyond amazing. Form handling, data validation, session management, authentication, database communication and much more was a breeze. Going from writing your own code and building your own logic for some of those aspects, to using a PHP web application framework that handles all of this is one helluva big step up.<\/p>\n<p><!--more--><\/p>\n<p>In the past, I&#8217;ve fiddled around with <a href=\"http:\/\/cakephp.org\" title=\"CakePHP\">CakePHP<\/a> and slightly got my feet wet with <a href=\"http:\/\/symfony.com\" title=\"Symfony\">Symfony<\/a> and I must say, I was impressed. Only recently, I embraced an MVC (Model View Controller) way of life. It sets and defines clear boundaries on the type of code you can write and where. The Model is the code you write to interact with the database. View is code written for displaying your content. Controller is the logic that ties it all together between the View and the Model. I caught myself a couple times writing controller code within the model.<\/p>\n<h2>Example of Controller Code<\/h2>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nclass Customer extends CI_Controller {\r\n\t\r\n\tpublic function __construct() {\r\n\t\tparent::__construct();\r\n\t\t\/\/Loading the Customer Model so we can interact with database\r\n\t\t$this-&gt;load-&gt;model('customer_model');\r\n\t}\r\n\r\n\tpublic function create_customer() {\r\n\t\t\/\/Create a customer array and pass in values to the\r\n\t\t\/\/create method in the model. Field names in the database\r\n\t\t\/\/table are specified as keys in the array here.\r\n\t\t$customer_data = array(\r\n\t\t\t'first_name' =&gt; &quot;Gary&quot;,\r\n\t\t\t'last_name' =&gt; &quot;Raymond&quot;,\r\n\t\t\t'company' =&gt; &quot;The Man on the Visa Card&quot;,\r\n\t\t\t'email_address' =&gt; &quot;garyraymond@visa.com&quot;,\r\n\t\t);\r\n\t\treturn $this-&gt;customer_model-&gt;create_customer($customer_data);\r\n\t}\r\n}\r\n<\/pre>\n<h2>Example of Model Code<\/h2>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nclass Customer_model extends CI_Model {\r\n\t\r\n\tpublic function __construct() {\r\n\t\t$this-&gt;load-&gt;database();\r\n\t}\r\n\t\r\n\tpublic function create_customer($customer_data) {\r\n\t\t\/\/Specifying the table that customer information will be saved.\r\n\t\t\/\/Pass in array received from controller\r\n\t\treturn $this-&gt;db-&gt;insert('customer', $customer_data);\r\n\t}\r\n}\r\n<\/pre>\n<p>All in all, it&#8217;s a great framework and has already simplified many of the tasks I&#8217;ve been working on. The <a href=\"http:\/\/ellislab.com\/codeigniter\/user-guide\/index.html\" title=\"CodeIgniter User Guide\">documentation<\/a> is superb and the resources are on point. If you&#8217;re not into learning a new way of coding, or a templating language, but want to take advantage of a rich set of libraries, I recommend you take CodeIgniter for a spin.<\/p>\n<p>All of the other frameworks I mentioned are just as amazing. I&#8217;ll post a more indepth piece on CodeIgniter and eventually, the other frameworks (if I get around to using it).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CodeIgniter is a PHP web application framework that enables you to build applications much faster and has rich libraries and superb documentation.<\/p>\n","protected":false},"author":2,"featured_media":3374,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[152],"tags":[411,410,408,409,22,412,413],"_links":{"self":[{"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/posts\/3373"}],"collection":[{"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/comments?post=3373"}],"version-history":[{"count":13,"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/posts\/3373\/revisions"}],"predecessor-version":[{"id":3858,"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/posts\/3373\/revisions\/3858"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/media\/3374"}],"wp:attachment":[{"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/media?parent=3373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/categories?post=3373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/tags?post=3373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}