CodeIgniter is a really simple to use PHP web application framework.  I just started using it last week for the first time. I dont usually blog about a subject I’m new to, but I wasn’t able to find one location to answer this question, I felt i should jot down these notes in case someone else out there had my problem.

CodeIgniter is really easy to use. It allows you to create a PHP site pretty quickly. Along with following the MVC pattern a lot more strictly, CodeIgniter comes with an assortment of helper libraries that are really easy to use. Go checkout CodeIgniter.com to get a better feel for it.

Although I like the simplicity of using TextMate as a simplified IDE, there are times I’d like to be able to step through my code and make sure things are working right. What i want to talk about here is to get your environment setup to use CodeIgniter with NetBeans. NetBeans recently added functionality to allow for code completion when coding against CodeIgniter libraries. Not all work perfectly, but its a great way to understand the framework.  What we are going to do is walk through how to get you up and running and attaching to the debugger.

I’ve only done this on a Mac, so my apologies to windows users. I’m running on Snow Leopard, but this should work on previous versions as well.

1. Download the codeigniter source.

2. Download Netbeans 6.9 with PHP support or higher.

3. Make sure you have xdebug installed and configured with your PHP. For more info on that, go here. 

4. Go to Netbeans->Preferences->PHP->General. Make sure your PHP 5 interpreter path is correct. Set your debugger port to 9000 and ensure Session ID is ‘netbeans-xdebug’. I would also unclick "Stop at the first line" because I find that a little annoying to stop there everytime a breakpoint is set. Its good to see it for the first time just to know where your code starts, but thereafter its not necessary.

5. Now the default settings of codeigniter is to disregard GET (query) parameters. This is problematic because for Netbeans to attach to the xdebug, it needs to pass in the following query parameters: XDEBUG_SESSION_START=netbeans-xdebug. With the default settings, this causes a 404 error. So to get around this, while preserving the nice URL segment based settings that come pre-baked into codeigniter, go to the config.php file under /application/config and change the following values:

$config['uri_protocol'] = "PATH_INFO";
$config['enable_query_strings'] = TRUE; 

6. Now place your breakpoint wherever your heart desires. And copy your URL into a browser, or curl. Make sure to append ?XDEBUG_SESSION_START=netbeans-xdebug at the end of it.

I’m a bit annoyed that i have to pass in a query parameter to be able to attach to a debugger, but since this will only come in handy occasionally, it seems like a necessary evil. XDebug actually has a lot more power stuff in it, which will be handy in more cases than attaching a debugger.