Posted 08.18.2011

Building a Basic Blog in Code Igniter (Part 4)

I keep promising I’ll do better on finishing this series, but 3 more months have gone by (so sorry!) — Well, let’s actually make it happen.

So, we’re building a blog in CodeIgniter.

So far, we’ve covered:

Today, we’ll look at getting our config file set up to talk to that database we built.


Go to your site files. Go to system > application > config >

There are two files that we’ll be concentrating on: config.php and database.php

Let’s open up config.php first.

The first order of business is fixing the base url on line 14. In my case, I’ll change it to http://localhost/awesome_ci/ If you’re using MAMP (I wrote a post about getting MAMP up running), then your address will probably look something closer to http://localhost:8888/awesome_ci/ (In either case, make sure you leave that / on the end!)

Next, scroll down to line 220 and look at the Encryption Key. Depending on the type of project you’re working on, you might not need this, but let’s go ahead and set it for fun.

One of the (many) things I love about CodeIgniter, is that they’re code is well documented. Straight from their documentation:

To take maximum advantage of the encryption algorithm, your key should be 32 characters in length (128 bits). The key should be as random a string as you can concoct, with numbers and uppercase and lowercase letters. Your key should not be a simple text string. In order to be cryptographically secure it needs to be as random as possible.

To keep my keys as random as possible, I’ll typically use a generator. A quick google search returned randomkeygen.com. There’s even a section there for CodeIgniter Encryption Keys. Perfect!

Pick one of the 3 options there and copy and paste it into your config file.


That was easy.


Now, let’s look at the database.php file. This is pretty straight forward too. Scroll down to line 40.

The first thing you have to do is set your database host. If you’re developing locally, it will stay “localhost.” However, if you’re building the site online, this might look different. You’ll have to check GoDaddy or MediaTemple or HostGator or whoever’s documentation.

On line 41 and 42, you need to set your username and password. If you’re running MAMP, it will actually tell you all this information on the start screen.

On line 43, you’ll set the name of the database. If you’re following along, in Part 3, we named our databae awesome_ci.

When you’re done, your file should look like this:

I told you it wasn’t anything crazy! Our config file is now up and running.


So you’ll believe me when I say I’ll actually finish this series. Here’s what’s coming up:

  • Building the blog listing page
  • Building the back end (Part 1)
  • Building the back end (Part 2)
  • Building an individual blog post page with comments
  • Finishing Touches
  • Other Tips and Tricks: Creating a United States library
  • Other Tips and Tricks: Auto Complete
  • Other Tips and Tricks: AJAX

So, get excited!