CodeIgniter通过uri段编码字符串?

| 我是Codeigniter的新手,正在为网站添加搜索功能,并且有两个问题。 我将如何提交表单,以便将其作为uri段发送(如查询字符串)?我之前通过提交post并在uri段中将其重定向到url来做到这一点。但是有更好的方法吗? 如何通过uri段发送字符串(例如完全由用户生成的搜索查询)?我尝试了urlencode,但是仍然有不允许的字符。我想保留大部分查询内容(因此很容易在历史记录中找到它,所以没有base64_encode)。有什么想法吗?有内置的功能吗? 谢谢你的帮助, 最高     
已邀请:
        您将使用JavaScript形成URL,如下所示:
<form onsubmit=\"window.location.href=\'/search/\'+encodeURIComponent(document.getElementById(\'search_query\').value);return false\">
    <input id=\"search_query\" type=\"text\" />
    <input type=\"submit\" />
</form>
编辑:由于CodeIgniter的URI过滤器,以上答案将无法正常工作。但是,根据我对1.7版的经验,如果传递多个GET参数,则可以使用$ _REQUEST数组检索它们。这将完全绕过URI过滤器。这样做:
<form action=\"/search\">
    <input name=\"x\" type=\"hidden\" />
    <input name=\"q\" type=\"text\" />
    <input type=\"submit\" />
</form>
然后使用$ _REQUEST [\'q \']进行搜索。希望这对您有用。     
         是。使用
method=\"get\"
创建一个表格。 如果如上所述设置表单,则无需担心编码请求。 例:
<form action=\"example.php\" method=\"get\">
  <input type=\"text\" name=\"search\" />
  <input type=\"submit\" value=\"Search\" />
</form>
更新:以\“ CodeIgniter \”方式生成表单:
echo form_open(\'email/send\', array(\'method\' => \'get\'));
    
        如果您需要使用类似
index.php?c=search&m=search&q=wow
而不是CI \的默认URI段 您必须启用查询字符串。 您可以通过在
 application/config.php
$config[\'enable_query_strings\'] = FALSE;
并将其更改为
$config[\'enable_query_strings\'] = TRUE;
然后,您将可以使用查询字符串。 但是mots CI人更喜欢不使用查询字符串,我不确定为什么。     

要回复问题请先登录注册