An overview of CodeIgniter
You’re interested in this whole new idea of frameworks, but why spend time on the learning curve when the system you already have in place works fine? Well, you might find yourself using the same functions or classes over and over; modifications of simple tools you would think would already exist in PHP.
Well, frameworks are your solution. A framework provides all the standard functions you would (hope would be included) in PHP, as well as a structured format for your files and directories. What are the advantages to this? Well, the code you need to handle cookies, sessions, dates, downloads, uploads, input, output, dates, pagination, templates and most security issues already exists in structured files. The only thing left is to make use of the provided functions.
CodeIgniter is an open source web application framework that helps you write kick-ass PHP programs.
The framework that I’m currently using the most is called CI, or CodeIgniter. It requires no use of the command line or any process installed on your server. It has a very well written documentation, a low footprint and happens to be one of the higher performing frameworks. What I find most attractive, however, is that rather than constricting you into a MVC model (more on this later), CodeIgniter simply presents the model to you, and it is up to the programmer to follow the model as loose or strict as they want.
The site I’m using CodeIgniter on is called VentStatus. VentStatus is a tool used to track the users and servers of a VOIP (voice over internet protocol) program called Ventrilo. Ventstatus constantly queries Ventrilo servers for things like their user count, their uptime, channels, and current users.
CodeIgniter is a good choice for this kind of website. An external process is called to check the status of servers, so CodeIgniter’s caching and speed helps to make up for lost time calling the process.
Most frameworks are based on the MVC framework. M stands for model, V for view, and C for controller, but, this isn’t exactly the way I would go about describing the MVC model to anybody.
I would start with the Controller part of MVC. The controller is what is responsible for converting the address bar into directions for your program. The first directory in a given URL specifies a file and class to call. The second directory specifies the function of that class to execute. For example, http://www.ventstatus.com/servers/status/ finds the servers.php file, calls the Servers class, and then executes the status function. Any directories given after /status/ are converted in to variables given to the status function. The advantage of this is what we call search engine friendly URLs, or URLs that are readable to humans, as well as search engines.
The next part to introduce would be the Model aspect of MVC. In my head models act as containers full of tools you’re able to make use of in any area of you web application. For example, in my users model, I have a list of functions that relate to manipulating user data. Some of my functions in include adding users, updating users, checking a users last online times and combinations of the past three based on input variables. This helps your program stay organized as you can call any set of tools you need as they are needed, rather than including mass amounts of functions that are unneeded in some areas of your site.
Last, but from my perspective one of the more important functions of CodeIgniter is the View part of MVC. The view part of CodeIgniter allows you to keep your content and presentation separate, which has been a repeated idea throughout design. All of your data is taken and made in Model and Controller, and theoretically there should be nothing left to calculate by the time View swings around. Thankfully though, CodeIgniter is not strict, and you can break the rules if you need to. A view page acts as a template for all the data outputted by the controller. So if you were to put somebody else in charge of site design who really had no idea how to program or wasn’t familiar with PHP, you could have them or anybody else work on the page without affecting any actual functioning code. This also allows you to make consistent header and footer templates to include on every page in your site, rather than coding the same thing over and over again.
Now one of the great things about CodeIgniter is the prewritten libraries and classes to help you write code more quickly. These range from database classes to text formatting. They can be included as needed, and really help simplify things. The whole point of CodeIgniter is to help you by not “reinventing the wheel” so to speak. You won’t waste time writing code that has already been written my thousands of programmers millions of times. You have more time to focus on the fun things like developing new software rather than trying to find out how to account for daylight savings time in Utah.
One of the most useful classes in CodeIgniter is what is called "Active Records" in the database class. Instead of wasting time debugging long database queries, Active Records lets you assign clauses as you need to, and execute the query whenever you want. It also includes shorthand functions for some more complicated but common database functions.
As I mentioned above, CodeIgniter also has great time zone management. Since all site users are on different time zones, any time stored in the database has to be based on the same standard time zone, and any time or date outputted must be custom tailored to each user. CodeIgniter includes a class which gives you a standard timestamp, as well as conversion to other time zones based on the user’s preference.
The View part of MVC is a great timesaver as well. Over the years I’ve developed my own template system. MVC allows for a standard template system for all of my projects. The template system also enables caching to boost site performance, and load times.
I’ve run into a few hills while working on VentStatus, but the time CodeIgniter has saved me while developing makes up for it and then some.
CodeIgniter is definitely the solution for a developer looking for a speedy, useful, easy going framework with a minimal learning curve.
For one, the way CodeIgniter formats its URLs is a little buggy, not to mention confusing. For example, anything that is not an image, php, css, or html document is routed through CodeIgniter’s URL system. Linking to something like a pdf in a subdirectory of your web server won’t work unless you add an exception to your .htaccess file or CodeIgniter files. There may be tricks around this, but I haven’t looked too far into it yet. Another problem may be specific to my webhost (Dreamhost) who uses some non standard practices in their Apache setup. However, I found support quickly in CodeIgniter’s support forums.
Overall there isn’t much I can really say is bad about CodeIgniter. Nothing about CodeIgniter is mandatory. CodeIgniter is definitely the solution for a developer looking for a speedy, useful, easy going framework with a minimal learning curve.