如何在codeigniter中的索引函数中传递参数 [英] How to pass paramaters in index function in codeigniter
问题描述
以下是网址范例:
http://www.example.com/搜索/搜索关键字
我试图使这项工作,我删除了index.php使用.htaccess,搜索是控制器,我想在索引方法中传递一个参数。
I am trying to make this work, I removed the index.php using .htaccess, search is the controller and I want to pass a parameter in the index method.
这是目前的样子:
class Search extends CI_Controller{
function index($param){
echo $param;
}
}
有任何建议吗?
推荐答案
- 您需要
index
segmenthttp://www.mysite.com/search/index/search-keyword
。 - 或者你需要使用一个路由
$ route ['search /(:any)'] ='search / index / $ 1';
- 或者,您可以查看重新映射
- You need the
index
segmenthttp://www.mysite.com/search/index/search-keyword
. - Or you need to use a route
$route['search/(:any)'] = 'search/index/$1';
- Or you can look at remap
记住不要信任用户输入,尤其是当你把它放在你的url。最新版本的CI现在支持 $ _ GET
变量,因此您可能希望使用或 flashdata 。像 O'Brien
这样简单的搜索字词会给您一个致命错误(您提交的URI不允许使用字符。)。
Remember not to trust user input, especially when you are throwing it into your url. The latest version of CI supports $_GET
variables now, so you may want to look into using that or flashdata. A searh term as simple as O' Brien
will give you a fatal error ("The URI you submitted has disallowed characters.").
这篇关于如何在codeigniter中的索引函数中传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!