Tuesday, April 5, 2011

Using a Query String with Segmented Controller/Method URLs in CodeIgniter

CodeIgniter has some awesome segmented URL functionality baked into its core, but sometimes you want to be able to do things like this:


You can do so easily by doing the following:
  1. In config.php change:
    • $config['enable_query_strings'] to TRUE
    • $config['uri_protocol'] to 'PATH_INFO'
  2. In your controller:
    • Fetch the query string using $this->input->get('some');
      (this example corresponds with the above URL)

And that's all folks! It works when a query string isn't present, it works with any number of query string variable pairs, it works with method parameters (e.g. /my_controller/my_method/my_param?some=more). It just works! Sweet, eh?

No comments: