Getting Started With CodeIgniter – 1

Installing CodeIgniter – a PHP Framework – On Your PC

First, be aware, I am not a CodeIgniter expert. I am a relatively new user and am just trying to find my way around it.  This series of posts is to give you a blow by blow account of how I am putting a CodeIgniter web site together, in real-ish time. If I succeed it will mean anyone can do this.

If you are new to PHP and want to get a head start, but think a framework is just too difficult, I am going to attempt to get you started. (Famous last words).  For a real CodeIgniter experts visit the CI forums.

CodeIgniter has to be the easiest PHP framework to install.  This is why it is my framework of choice. I am going to explain how to set it up locally to run on a PC. Before you start you are going to need the following:

  • PHP installed on your local computer and on your web server (PHP 4.3.2 at least), and a database, (MySQL 4.1 at least). There is more information in the user guide about support for other databases.
  • A PHP/HTML editor. I either WeBuilder. There are other arguably better development environments, but I lose patience with the difficulty to install them, and the mass of software to install to make the run in debug mode. This means I tend to debug in my head and with various output statements. Stone Age I know, but it hasn’t caused me any problems so far.
  • A root directory where your local web server expects to find sites you run locally.

My local web server root directory is : C:\Users\Lizzy\Documents\websites and this is where my local installation of Apache has its root directory set.
Code Igniter Directory Structure

  1. Download the latest version of CodeIgniter from the CodeIgniter Web Site. At the time of writing this was version 1.7.0
  2. Decide on a name for the new web site you are about to create using CodeIgniter. In my example this will be chaingang3, but obviously you will choose your own, and substitute that where I have chaingang3.
  3. Unzip the entire contents of the CodeIgniter zip file into local root directory (as specified in your httpd.conf file if you are running Apache). For example in my httpd.conf file, DocumentRoot is “C:\Users\liz\Documents\Websites” so I unzipped the CodeIgniter installation to that location.
  4. Once unzipped, rename the CodeIgniter_1.7.0 directory to the name of your web site. In my case I renamed it to chaingang3.
  5. You’ll end up with a directory structure looking like the image on the right within your root directory, wherever yours is.
  6. Next you have to configure CodeIgniter. This is easy to do. Open up the config directory that you can see within the application directory and open the file called config.php

Changes to Config.php

config.php locationThe only changes you need to make to this file (to begin with) are are shown here in the Base Site URL section. You’ll find config.php in the directory as shown by the pink arrow on the right.

You just specify the starting position of the site on your local machine, and also on its ultimate server destination.

Base_URL

Note that I put two base_url values and some code to decide which is applicable, either locally or on the web server.

OK – that’s it for now. I have to drive to Exeter to meet my husband on the train.

Next post will be getting the CSS and other supporting directories in, the database and getting the system to run.

if($_SERVER['HTTP_HOST'] == "localhost"){
  $config['base_url']="http://localhost//chaingang3/";
}
else{
  $config['base_url']='http://www.chaingang.com/';
}

Code Igniter – The MVC Model and Me

It’s early days, but at the moment I think I made the right decision to choose Code Igniter.

The forum on the CI site is friendly and very helpful. The site and the people involved get straight to the point. Everyone says the CI documentation is excellent – here I beg to differ a little. I find it clearly written but sparse. But as I become more proficient I suspect I will start to appreciate that aspect of it. I have also found that code examples are limited (unless they are lying around somewhere and I just haven’t found them).

I’ve spent some time lurking in the CI forum trying to map my confusions to those of people that went before me. I have had limited success retro-fitting my questions to existing questions but I feel this learning curve is necessary to avoid asking completely stupid questions on the forum myself. I figure that I am having problems getting started because I have never done any real OO programming, nor had I had any MVC before last week.

. . . . . .

I started writing this post a couple of days ago, and now I feel slightly less confused as I am starting to pick up the basics just by reading the forums.

What follows sums up how I feel about Code Igniter at the moment.

Grateful - I am grateful that someone (Rick Ellis) decided to write CI, making it as loosely coupled as it is, thus still leaving the coder some freedom to make decisions, and to make it as nonsense-free as he has.

Happy - I am delirious that Code Igniter took about 25 seconds to install with no edits to php.ini, no DLLs to download, no services to start, stop or resurrect, no digging around in Google attempting to track down exotic installation problems.

Excited - I am looking forward to having CI drag me into MVC methodology, however loosely.