I have recently started using Codeigniter, and found it to be an incredibly powerful framework. Some people argue that lazy people use frameworks, but personally I think it stops you from having to re-invent the wheel everytime you start a new project.
Setting Codeigniter Up
Setting up Codeigniter is actually quite easy. All you really need to do is open the zip file, and extract the contents to a folder. I advise using a local server to get used to working with Codeigniter. In fact I use a localhost to do all my coding before putting it on the web. I recommend Xampp which will even run from a USB flash drive.
Once you have extracted everything from the zip you can delete the user_guide folder if you like since you always have access to a up-to-date version via the Codeigniter website.
Editing The Config File
The next step is to edit the main config file to get everything working. You can find the config file in
You will find
$config['base_url'] = 'http://127.0.0.1/Codeigniter/' at the top of the file. This must equal the path to the folder in which Codeigniter is installed. So if you are running a localhost, and you place Codeigniter in a folder called ‘codeigniter’ the path might be
The other thing to change is the encryption key which is a little further down. You can find a random string generator here. Just pick 32 characters and tick uppercase & lowercase. Also if your PHP installation doesn’t support short php tags you can have Codeigniter dynamically re-write them so you can still use them.
Autoloading Codeigniter Libraries & Helpers
You don’t have to do this, but if you are using a database I recommend auto loading the database library. To do that open the
'autoload.php' file which is in the same location as before.
To auto load the database library look for
$autoload['libraries'] = array('');. Just put
database in between the single-quotes. Do Not Auto Load This Library If You Do Not Have Any Database Config’s Set As You Will Recieve Error Messages All The Time.
I highly recommend that you autoload the following helpers as they come in handy all the time. Find
$autoload['helper'] = array('');. This time just put
html in the array. You should end up with something like this
$autoload['helper'] = array('url', 'html');.
Adding Database Connection Info
If you do need to use database connection in Codeigniter you will need to add your connection information into the
'database.php' file which is in the same directory as before.
All you need to do is add in your connection information. I’m sure you know what everything is by now, but if you need a detailed description this page on the Codeigniter user docs give a better description than I ever could.
Well that’s it for now. I will do part 2 at a later date, but until then I hope you have enjoyed this tutorial, and if you have anything to add please leave a comment.