Starting Out With Codeigniter Part 1

/ Misc / by Paul Robinson / 5 Comments
This post was published back on August 22, 2008 and may be outdated. Please use caution when following older tutorials or using older code. After reading be sure to check for newer procedures or updates to code.
This is a very old tutorial & Codeigniter has matured a lot since this post was written. I would strongly advise to look elsewhere for more up-to-date tutorials on Codeigniter. Unfortunately I do not have any newer tutorials on Codeigniter as I no longer use it. Instead I now use Laravel.

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.

Getting Codeigniter

The only place I advise you get Codeigniter from is the official Codeigniter website. Also while you are there give the very, very helpful user documentation a quick look over.

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 'system/application/config/config.php'.

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 'http://localhost/codeigniter/'.

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 url, and 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.

5 Comments

Author’s gravatar

Nice post, i am beginner in codeigniter, this post help me a lot

Reply
Author’s gravatar author

No problem. I’m planning on doing some more codeigniter tutorials very soon. Let me know if there is anything in particular you’d like me to cover.

Author’s gravatar

Your post its great and it helped me a lot with my research related to codeigniter. Thanks, and more power to your blog!

Reply
Author’s gravatar

I also created a tutorial for the CI beginner here. You can also learn in my post. Thank!

Reply
Older Comments
Newer Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

I'll keep your WordPress site up-to-date and working to its best.

Find out more