[英]CodeIgniter encode string through uri segment?
I am new to codeigniter, I am adding a search function to the site, and had two questions. 我是Codeigniter的新手,正在向网站添加搜索功能,并且有两个问题。
Thanks for any help, Max 谢谢您的帮助,麦克斯
You would use JavaScript to form the URL, like this: 您将使用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>
EDIT: The above answer will not work because of CodeIgniter's URI filter. 编辑:上面的答案将由于CodeIgniter的URI过滤器而无法工作。 However, from my experience with version 1.7, if you pass more than one GET parameter, you can retrieve them using the $_REQUEST array.
但是,根据我对1.7版的经验,如果传递多个GET参数,则可以使用$ _REQUEST数组检索它们。 This will bypass the URI filter altogether.
这将完全绕过URI过滤器。 So do this:
这样做:
<form action="/search">
<input name="x" type="hidden" />
<input name="q" type="text" />
<input type="submit" />
</form>
Then use $_REQUEST['q'] to get your search query. 然后使用$ _REQUEST ['q']进行搜索。 Hopefully this will work for you.
希望这对您有用。
method="get"
. method="get"
创建一个表单。 Example: 例:
<form action="example.php" method="get">
<input type="text" name="search" />
<input type="submit" value="Search" />
</form>
Update : To generate the form the "CodeIgniter" way: 更新 :以“ CodeIgniter”方式生成表单:
echo form_open('email/send', array('method' => 'get'));
if you need to use something like 如果您需要使用类似
index.php?c=search&m=search&q=wow
instead of CI's default URI Segments 而不是CI的默认URI段
you have to enable query strings . 您必须启用查询字符串。 you can do it by changing some configuration in
您可以通过在
application/config.php
find 找
$config['enable_query_strings'] = FALSE;
and change it to 并将其更改为
$config['enable_query_strings'] = TRUE;
Then you will be able to use query strings . 然后,您将可以使用查询字符串。
but mots CI people prefer not to use query strings, I am not sure why . 但是mots CI人更喜欢不使用查询字符串,我不确定为什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.