I understand that CI is mostly URL segment based, but I want to have a query string: blahblah.com/search.html?q=keyword
When I try $this->input->get( "q" ), it returns empty. Is there a route or something I need to configure?
I understand that CI is mostly URL segment based, but I want to have a query string: blahblah.com/search.html?q=keyword
When I try $this->input->get( "q" ), it returns empty. Is there a route or something I need to configure?
You have to enable query strings
CodeIgniter optionally supports this capability, which can be enabled in your application/config.php file. If you open your config file you'll see these items:
$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
If you change "enable_query_strings" to TRUE this feature will become active. Your controllers and functions will then be accessible using the "trigger" words you've set to invoke your controllers and methods:
index.php?c=controller&m=method
Example: index.php?c=products&m=view&id=345
The best way to get query strings working in CodeIgniter is to use Google. This question is asked (and answered) on the forums, here and on twitter at least 10 times a day.
There are a few methods, but recently I am a fan of the following method:
http://www.dijexi.com/2009/08/how-to-mix-segment-and-query-string-in-codeigniter/
I prefer this over others as it will have no application-wide effects like some other approaches and it won't require any crazy hacking to get it working.
If you want this $_GET support throughout the entire app, just put the parse_str into MY_Controller or a pre_controller hook.