如何在Codeigniter的索引函数中传递参数 [英] How to pass parameters in index function in codeigniter

查看:85
本文介绍了如何在Codeigniter的索引函数中传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是url的示例: http://www.example.com/search/search-key

here's an example of url: http://www.example.com/search/search-keyword

我正在尝试使其工作,我使用.htaccess删除了index.php,搜索是控制器,我想在index方法中传递参数.

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;
    }

}

有什么建议吗?我似乎无法使其正常工作

any suggestions? I can't seem to make it work

推荐答案

  • 您需要indexhttp://www.example.com/search/index/search-keyword.
  • 或者您需要使用路线$route['search/(:any)'] = 'search/index/$1';
  • 或者您可以查看重新映射
    • You need the index segment http://www.example.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这样简单的searh术语将给您带来致命错误(您提交的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屋!

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