Es Bueno is a weblog.

POWERED by FUSION

 July 6
2009




CodeIgniter & Query Strings

I have been living in CodeIgniter for the past month or so now.  I love how it structures it’s URLs into search-engine friendly segments, ie. yourmom.com/is/awesome/ If you are at all familiar with MVC frameworks, you’ll recognize that ‘is’ is the controller, and ‘awesome’ is your function you are calling inside that controller.  Isn’t that grand?

However, what if you need your URL structure in the standard query string format?  I ran into this exact problem the other day when I was using a jQuery Auto-Suggest plugin, and it was hard wired (so to speak) to accept a parameter like so:

yourmom.com/is/awesome/?q=Lookup Value Goes Here

Trouble here is that CodeIgniter play well with mixed structures.  Thankfully, the fine folks at Ellis Lab thought of that already, and inside the config.php file, you will find something like this:

Query Strings in CodeIgniter

By setting ‘enable_query_strings’ to TRUE, you can let CodeIgniter auto-detect the URL structure and conveniently assign parameter names for your controllers and functions.  Now I can go to yourmom.com/?c=is&m=awesome just as I went to yourmom.com/is/awesome/ in the example at the top.  And to take it a step further, I can now pass in my ‘q’ parameter for the Auto-Suggest plugin I was using.

I couldn’t be more happy with the CodeIgniter framework and I highly recommend it to anyone looking to try out a new development environment.