[英]CodeIgniter encode string through uri segment?
我是Codeigniter的新手,正在向网站添加搜索功能,并且有两个问题。
谢谢您的帮助,麦克斯
您将使用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人更喜欢不使用查询字符串,我不确定为什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.