如何在 CodeIgniter 中使用 GET 表单? [英] How can I use GET forms with CodeIgniter?

查看:22
本文介绍了如何在 CodeIgniter 中使用 GET 表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 CI 主要基于 URL 段,但我想要一个查询字符串:blahblah.com/search.html?q=keyword

I understand that CI is mostly URL segment based, but I want to have a query string: blahblah.com/search.html?q=keyword

当我尝试 $this->input->get( "q" ) 时,它返回空.是否有路线或我需要配置的东西?

When I try $this->input->get( "q" ), it returns empty. Is there a route or something I need to configure?

推荐答案

在 CodeIgniter 中获取查询字符串的最佳方法是使用 Google.每天至少 10 次在论坛、此处和 Twitter 上提出(并回答)这个问题.

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.

如果您希望在整个应用程序中都支持 $_GET,只需将 parse_str 放入 MY_Controller 或 pre_controller 钩子中.

If you want this $_GET support throughout the entire app, just put the parse_str into MY_Controller or a pre_controller hook.

这篇关于如何在 CodeIgniter 中使用 GET 表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆