Php 如何在codeigniter中生成动态表单动作地址?

Php 如何在codeigniter中生成动态表单动作地址?,php,codeigniter,Php,Codeigniter,我在我的网站上有一个搜索表单,它如下所示: <form action="/search/results"> <input type="text" name="keyword"> <button type="submit"> // etc... </form> 但是有可能使结果页面URL看起来像 mysite.com/search/results/keyword 我会使用jQuery $('#myform').submit(function()

我在我的网站上有一个搜索表单,它如下所示:

<form action="/search/results">
<input type="text" name="keyword">
<button type="submit">  // etc...
</form>
但是有可能使结果页面URL看起来像

mysite.com/search/results/keyword
我会使用jQuery

$('#myform').submit(function(){
    $(this).attr('action', $(this).attr('action') + "/" + $(this).find(input[name="keyword"]).val());
});
另一种可能是在控制器中创建一个代理方法,如果您希望在url中包含所有的post值,那么它很有用:

public function post_proxy() {
    $seg1 = $this->input->post('keyword');
    $seg2 = $this->input->post('keyword2');
    $seg3 = $this->input->post('keyword3');

    redirect('my_method/'.$seg1.'/'.$seg2.'/'.seg3);
}
在这种情况下,我将在post数据中使用数组来简化代码:

<input type="text" name="kw[1]">
<input type="text" name="kw[2]">
<input type="text" name="kw[3]">

$segment_array = $this->input->post('kw');
$segments = implode("/", $segment_array);
redirect('my_method'.$segments);

$segment_array=$this->input->post('kw');
$segments=内爆(“/”,$segments\u数组);
重定向('my_method'.$segments);

是的,我知道->但我的问题是如何使表单重定向到这个地址?@Yan我想Pawel是在问如何创建一个友好的URL,而不是如何传递额外的信息。我对它没有做太多的工作,但我很确定这是在询问基于get data的htaccess重写。我希望它在按下submit按钮后让我进入/search/results/keyword:)是应该以这种方式传递的唯一关键字,还是任何其他表单数据?有什么区别?我还有两个字段要传递:)我喜欢post_代理解决方案:)
<input type="text" name="kw[1]">
<input type="text" name="kw[2]">
<input type="text" name="kw[3]">

$segment_array = $this->input->post('kw');
$segments = implode("/", $segment_array);
redirect('my_method'.$segments);