{"id":1598,"date":"2019-03-13T06:53:06","date_gmt":"2019-03-13T14:53:06","guid":{"rendered":"https:\/\/www.nicknguyen.com\/?p=1598"},"modified":"2019-11-16T15:34:05","modified_gmt":"2019-11-16T23:34:05","slug":"why-using-frameworks-is-a-must","status":"publish","type":"post","link":"https:\/\/nicknguyen.com\/old\/why-using-frameworks-is-a-must\/","title":{"rendered":"Why using Frameworks is a MUST"},"content":{"rendered":"<p>A coders example of why frameworks are a MUST in application development.<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>Frameworks reduce the amount of code required to complete a task.<\/li>\n<li>It reduces the overhead cost and time (learning curve) of bringing onboard new developers to an existing project<\/li>\n<li>Helps keep your code clean and organized as your project grows<\/li>\n<li>The more displined you are in adhering to MVC pattern, means less time and less cost in future development<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><a href=\"https:\/\/codeigniter.com\/user_guide\/general\/welcome.html\">CodeIgniter<\/a> is right for you if:<\/p>\n<ul class=\"simple\">\n<li>You want a framework with a small footprint.<\/li>\n<li>You need exceptional performance.<\/li>\n<li>You need broad compatibility with standard hosting accounts that run a variety of PHP versions and configurations.<\/li>\n<li>You want a framework that requires nearly zero configuration.<\/li>\n<li>You want a framework that does not require you to use the command line.<\/li>\n<li>You want a framework that does not require you to adhere to restrictive coding rules.<\/li>\n<li>You are not interested in large-scale monolithic libraries like PEAR.<\/li>\n<li>You do not want to be forced to learn a templating language (although a template parser is optionally available if you desire one).<\/li>\n<li>You eschew complexity, favoring simple solutions.<\/li>\n<li>You need clear, thorough documentation.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>Now for the good stuff&#8230;<\/p>\n<h2><strong>Querying Data from SQL<\/strong><\/h2>\n<h3>CodeIgniter (4 Lines of code)<\/h3>\n<pre><code>\r\n$query = $this-&gt;db-&gt;get('table_name');\r\nforeach ($query-&gt;result() as $row)\r\n{\r\necho $row-&gt;title;\r\n}\r\n<\/code><\/pre>\n<h1>VS<\/h1>\n<p><strong>PHP<\/strong> (LOTS OF LINES OF CODE) Using Codeigniter all the configuartion settings are automatically loaded and avaliable EVERYWHERE and ANYWHERE<\/p>\n<pre><code>$servername = \"localhost\";\r\n$username = \"username\";\r\n$password = \"password\";\r\n$dbname = \"myDB\";\r\n\r\n\/\/ Create connection\r\n$conn = new mysqli($servername, $username, $password, $dbname);\r\n\/\/ Check connection\r\nif ($conn-&gt;connect_error) {\r\ndie(\"Connection failed: \" . $conn-&gt;connect_error);\r\n}\r\n\r\n$sql = \"SELECT id, firstname, lastname FROM MyGuests\";\r\n$result = $conn-&gt;query($sql);\r\nif ($result-&gt;num_rows &gt; 0) {\r\n\/\/ output data of each row\r\nwhile($row = $result-&gt;fetch_assoc()) {\r\necho \"id: \" . $row[\"id\"]. \" - Name: \" . $row[\"firstname\"]. \" \" . $row[\"lastname\"]. \"&lt;br&gt;\";\r\n}\r\n} else {\r\necho \"0 results\";\r\n}\r\n$conn-&gt;close();\r\n<\/code><\/pre>\n<p><a href=\"https:\/\/codeigniter.com\/user_guide\/database\/index.html\">This is just one example, to learn more about working with SQL via codeigniter<\/a><\/p>\n<h2><\/h2>\n<h2>HELPERS<\/h2>\n<p>Toolbox of useful Code aka Collection of Functions that help simply coding such as<br \/>\nDealing with Dates, Arrays, HTML, Forms, Cookies, Sessions, etc<\/p>\n<h3>Example Dates HELPER<\/h3>\n<pre><code>\r\n\/\/Makes all Date Helper Functions readily avaliable\r\n$this-&gt;load-&gt;helper('name');\r\n\r\n$bad_date = '199605';\r\n\/\/ Should Produce: 1996-05-01\r\n$better_date = nice_date($bad_date, 'Y-m-d');<\/code><\/pre>\n<p><a href=\"https:\/\/codeigniter.com\/user_guide\/helpers\/index.html\">For a complete list of CI helpers available<\/a><\/p>\n<p>&nbsp;<\/p>\n<h2><strong>Libraries (Object Oriented Library of Common Tools)<\/strong><\/h2>\n<h3>Example of sending complex emails<\/h3>\n<pre><code>\r\n\/\/Load Library\r\n$this-&gt;load-&gt;library('email');\r\n\r\n$this-&gt;email-&gt;from('your@example.com', 'Your Name');\r\n$this-&gt;email-&gt;to('someone@example.com');\r\n$this-&gt;email-&gt;cc('another@another-example.com');\r\n$this-&gt;email-&gt;bcc('them@their-example.com');\r\n\r\n$this-&gt;email-&gt;subject('Email Test');\r\n$this-&gt;email-&gt;message('Testing the email class.');\r\n\r\n$this-&gt;email-&gt;send();\r\n<\/code><\/pre>\n<p>Without Framework you would have to add third party files SUCH as PHPMailer and add Includes on top of each page, coding alot more method calls<\/p>\n<h3>PAGINATION LIBRARY Codeigniter<\/h3>\n<pre><code>\r\n$this-&gt;load-&gt;library('pagination');\r\n\r\n$config['base_url'] = 'http:\/\/example.com\/index.php\/test\/page\/';\r\n$config['total_rows'] = 200;\r\n$config['per_page'] = 20;\r\n\r\n$this-&gt;pagination-&gt;initialize($config);\r\n\r\necho $this-&gt;pagination-&gt;create_links();\r\n<\/code><\/pre>\n<p><a href=\"https:\/\/codeigniter.com\/user_guide\/libraries\/index.html\" target=\"_blank\" rel=\"noopener noreferrer\">Check out the list of libraries for almost everything you could possibly need\u00a0<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A coders example of why frameworks are a MUST in application development. Frameworks reduce the amount of code required to complete a task. It reduces the overhead cost and time (learning curve) of bringing onboard new developers to an existing project Helps keep your code clean and organized as your project grows The more displined&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1600,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"Why","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[161,164],"tags":[179],"class_list":["post-1598","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-opinions","category-technology-opinions","tag-devops"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/media.nicknguyen.com\/wp-content\/uploads\/2019\/03\/13075742\/7-best-php-frameworks.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/nicknguyen.com\/old\/wp-json\/wp\/v2\/posts\/1598","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nicknguyen.com\/old\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nicknguyen.com\/old\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nicknguyen.com\/old\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nicknguyen.com\/old\/wp-json\/wp\/v2\/comments?post=1598"}],"version-history":[{"count":3,"href":"https:\/\/nicknguyen.com\/old\/wp-json\/wp\/v2\/posts\/1598\/revisions"}],"predecessor-version":[{"id":1800,"href":"https:\/\/nicknguyen.com\/old\/wp-json\/wp\/v2\/posts\/1598\/revisions\/1800"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nicknguyen.com\/old\/wp-json\/wp\/v2\/media\/1600"}],"wp:attachment":[{"href":"https:\/\/nicknguyen.com\/old\/wp-json\/wp\/v2\/media?parent=1598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nicknguyen.com\/old\/wp-json\/wp\/v2\/categories?post=1598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nicknguyen.com\/old\/wp-json\/wp\/v2\/tags?post=1598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}