【问题标题】:Doing A GET request in CodeIgniter using URI Segments使用 URI 段在 CodeIgniter 中执行 GET 请求
【发布时间】:2013-08-07 03:26:51
【问题描述】:

如果我有这样的表格:

<form method="GET">
    <input type="text" name="search" />
</form>

如果我提交它,它会生成一个这样的 URL:
http://exmaple.com/search/results?search=text1+text2

现在这不适用于我的代码。如何让它使用 URI Segments,所以生成的 url 看起来像这样:http://exmaple.com/search/results/search/text1+text2

更多说明 换句话说,我想要的是,当我使用简单的 html 表单执行 get 请求时,它生成的 url 看起来像 codeigniter 的 URL,即
example.com/class/function/param1/param2
而不是
example.com/class/function?param1&amp;param2

【问题讨论】:

  • 你试过在codeigniter中使用路由吗? http://ellislab.com/codeigniter/user-guide/general/routing.html
  • 我刚刚尝试添加这条路线:$route['search/results?search=(:any)'] = "search/results/search/$1"; 但它不起作用
  • 试试这个$route['search/results/search/(:any)'] = "search/results?search=$1"你换了他们..

标签: codeigniter codeigniter-url


【解决方案1】:
in your codeigniter config file $config['enable_query_strings'] is set to false, so the url looks like http://example.com/search/results/search/text1+text2

if you want url like http://example.com/search/resutls?search=text1+text2 then set $config['enable_query_strings'] to true;

【讨论】:

    【解决方案2】:

    使用codeigniter路由可以实现http://exmaple.com/search/results/search/text1+text2

    通过将其放入您的路线中

    $route['search/results/search/(:any)'] = "search/results?search=$1"
    

    【讨论】:

    • 我想你错过了理解我的问题。我想要的是,当我使用简单的 html 表单执行获取请求时,它生成的 url 看起来像 codeigniter 的 URL,即 example.com/class/function/param1/param2 而不是 `example.com/class/function?param1&param2
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-10
    • 2017-04-14
    • 2015-11-28
    • 2014-11-26
    • 2016-11-19
    相关资源
    最近更新 更多