开发者

How can I use GET forms with CodeIgniter?

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?


Why not make it http://mysite.com/search/keyword/


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

http://codeigniter.com/user_guide/general/urls.html


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜