I’ve been playing around with the Code Igniter Framework for PHP over the last couple of weeks, primarily because Net Tuts has a series of 6 high-quality screencasts showing off some basic functionality of the framework. Essentially, Code Igniter provides some additional functionality and provides a standardized means of creating pages and methods using the MVC framework. If you’re not used to MVC, it’s a bit of an adjustment, but it can have some benefits on the testing side of things.
If you plan on doing any Code Igniter work, you’re going to need some form of development environment for it. On the Net Tuts tutorial, the author uses Text Mate, which works pretty well as a Mac product, but I’ve found that PHP Eclipse is a bit better of a solution as a development environment on the windows side. You’ll also need to get a copy of WAMP setup, get the CodeIgniter files and configure CodeIgniter to look at the right path on your web-server as well as the correct database.
Here’s how to setup the ultimate development and test environment for Code Igniter in Windows
Step 1: Installing Wamp
The first thing you’ll need to do is get a copy of WAMP. This stands for “Windows Apache MySQL and PHP”. It essentially provides a set of web-development framework that combines all of the tools that you need for creating a PHP test-bed in a Windows environment. Since Joomla is based on PHP, WAMP is a perfect solution to run Joomla on top of. You can download the installation files from WampServer.com
You will also be asked about SMTP information. Unless you have a specific need to do anything that involves sending emails from your web-server, it’s safe to leave those blank. If you are developing contact forms or somethign that would require credentials, you can get those from your internet service provider.
Step 2: Testing WAMP
After getting WAMP installed, you’ll be given the option of letting it start up automatically or you can simply launch WAMP from the start menu. Once you have the WAMP client running, you can enable the web-server and database by right clicking on the icon and clicking “Start All Services”. To make sure that the environment is working properly, right click the icon and select “Local Host.” If all is well, you’ll see a page that says “WAMPServer” that has a white-background.
Step 3: Getting Code Igniter
Once you have WAMP running, you’ll want to grab a copy of the Code Ingiter files from the Code Igniter Website. They typically come in the form of a ZIP file. Take the files in the Zip File and extract them to a sub directory of your WAMP installation’s WWW directory. Typically WAMP’s WWW directory is located at “c:\wamp\www\”, so a good directory to put your files in might be c:\wamp\www\ci\”.
Step 4: Testing Code Igniter
The next thing that you want to do is to test out your copy of Code Igniter on WAMP and make sure that it’s running properly. You can do this by opening up your web-browser and navigating to “http://localhost/ci/” (assuming that you named your Code Igniter file “ci”). If it’s working, it should look like this:
Step 5: Configuring Code Igniter
Once you have code igniter working, you’ll want to make a few modifications to Code Igniter’s config file so that Code Igniter is properly configured and can access your database.
The first file you want to modify is “config.php”, this is located in “/system/application/config/” relative to your root directory of code igniter, for us, that would be “C:\wamp\www\ci\system\application\config.”
On line 14, you’ll notice:
$config[‘base_url’] = “http://example.com/”;
We’ll want to change that URL to the URL of our code igniter install, so it should be:
$config[‘base_url’] = “http://localhost/ci”;
Step 6: Database Configuration
Finally, we’ll want to point Code Igniter at a database if we want to use one. Code Igniter by it self does not require a database, but if you want to do a project that requires database access, WAMP comes with MySQL Server, which will work just fine for a development environment.
To connect Code Igniter to a database, you’ll want to look at lines 40-43 of “database.php”, which is also located in Code Igniter’s config directory. We need to setup a username and password and choose which database we want to make use of. WAMP’s default MySQL username and password is “root” and nothing, so enter those in for your local environment. You’ll also want to make sure that your host name is set to localhost and that your database name is set to the database that you create.
$db[‘default’][‘hostname’] = “localhost”;
$db[‘default’][‘username’] = “root”;
$db[‘default’][‘password’] = “”;
$db[‘default’][‘database’] = “DATABASENAMEHERE”;
Step 7: Choosing an Editor
Right now, you have everything you need to start developing in Code Igniter, but you’re probably going to want some form of editor that will make your life a lot easier. The one I like to use is PHP Eclipse, which can be download from eclipse.org. Other editors you might want to try include TextPad, and TextMate.
Step 8: Making Your First Program
Now that your development and hosting environment is ready to go, you can start writing some code. To write your first “Hello World” program, head on over to Net Tuts and watch “CodeIgniter From Scratch: Day 1“.