【问题标题】:Searching with Codeigniter using the url to include disallowed URI characters使用 url 使用 Codeigniter 搜索以包含不允许的 URI 字符
【发布时间】:2012-03-26 14:30:36
【问题描述】:

我想使用 url 字符串中的搜索词在 codeigniter 中实现搜索,但在允许不允许的 uri 字符时遇到问题(' 是主要问题)

例如www.example.com/search/find/search_term/collector's edition/category/stackoverflow

基本上在'stackoverflow'类别中找到'collector's edition'

这会引发 URI 异常错误 - 即使我使用 javascript codeigniter 对其进行编码,也会将其取消编码。显然我不想去允许所有角色。

我还希望能够在数据返回时对其进行解码,这样我也可以在输入框中显示搜索词。

【问题讨论】:

    标签: codeigniter url search uri encode


    【解决方案1】:

    使用查询字符串而不是与 CI 建议的允许 URI 字符作斗争:

    example.com/search/?search_term=collector's+edition&category=stackoverflow

    只要确保您启用了查询字符串 ($_GET):

    $config['allow_get_array'] = TRUE; // This enables $_GET data
    
    // The name of this item is misleading, it's not what you might think 
    $config['enable_query_strings'] = FALSE; // <-- Ignore this, make sure it's FALSE
    

    然后抓取搜索词:

    $query = $this->input->get('search_term'); // No need to decode
    

    【讨论】:

    • 谢谢,我会看看通过你上面提到的 get 示例发送它
    【解决方案2】:

    您需要在 allowed_uri_chars 中添加“=”。您会在 config/config.php 文件中找到该字符串。

    它也可能是 . (点)在那里。尝试添加一个点。你需要有点勇敢 并尝试找出可行的方法。

    试试$config[‘permitted_uri_chars’] = ‘a-z 0-9~%.:?=_\-’;

    【讨论】:

    • 不确定在我的示例中您在哪里看到 = 或 .(dot) :我正在寻找一个不修改 allowed_uri_chars 的解决方案
    • 老兄,我不知道你在做什么,或者你在看什么 - 感谢您的尝试,但不要担心我已经涵盖了基础知识并且已经给出了尝试的解决方案
    猜你喜欢
    • 2015-06-29
    • 1970-01-01
    • 2013-04-22
    • 1970-01-01
    • 2023-03-20
    • 2013-12-10
    • 2015-07-10
    • 2019-11-17
    • 2012-03-09
    相关资源
    最近更新 更多