
|
|
|||
Rapid Application Development with CodeIgniterBy Akash Mehta2008-02-17
Introducing CodeIgniter! Before we delve into the internals of CodeIgniter, let's have a look at a quick sample of how it works. Grab a copy of CodeIgniter from CodeIgniter; I'll be working with version 1.6.1 in this example. Let's say we have a very basic application that takes a name via the URL and writes out, "Hello $name!". Here's how we would build it in just PHP, and then in PHP with CodeIgniter. Raw PHPindex.php:<?php Not exactly the best PHP script ever, but it should do for our demonstration. CodeIgniterCodeIgniter enforces consistent and effective file seperation from the ground up, with a simple filesystem structure as part of their implementation of MVC. The system/application folder has subfolders called 'controllers', 'models' and 'views'. system/application/controllers/hello.php<?phpsystem/application/views/show_name.php Here you can see we have two seperate files, which, as you might
have guessed, are the controller and view. The controller is entirely
OOP; the Notice that the view looks much cleaner than the echo calls we used earlier. Sure, you could jump in and out of PHP for that small example; maybe you only need one line of code to achieve the same functionality. Now, if your application is that simple and you aren't worried about XSS vulnerabilities, it's okay. However, our CodeIgniter version is better prepared to increase in complexity, with clean seperation between the business logic and the presentation. When we extend this in future, we can easily modify the frontend or the backend (or both) while making it easy to keep track of everything. Anyway, in this example, our controller class Hello is extending the
CodeIgniter class Controller giving it access to the framework core.
This includes functionality for input filtering, the library for which
is loaded at If I point my browser to Just a note on URLs: when you drop CodeIgniter into your website, it
takes over as the application entry point (from its root installation
directory, e.g. Notice the framework also handles clean search-engine-friendly URLs for us. Oh, and the glaring XSS vulnerability in our pure-PHP example earlier? Try putting anything vaguely harmful into the URL and CodeIgniter will reject it. It's XSS-proof already, with not a single input validation routine in sight. We've barely started and already CodeIgniter is making our life easier. Tutorial Pages: » Why should you be using CodeIgniter? » MVC 101 » Introducing CodeIgniter! » Getting our feet wet » Further CodeIgniter |
||||
| About the NetVisits, Inc Network | Write For Us | Advertise Copyright ©2007 NetVisits, Inc Network. All Rights Reserved. Privacy Policy. |
Visit other NetVisits, Inc. sites: |