3

私のサイトに検索フォームがあり、次のようになります。

<form action="/search/results">
<input type="text" name="keyword">
<button type="submit">  // etc...
</form>

mysite.com/search/results/投稿パラメータを処理するページが表示されます。もちろん、GETメソッド を使用することもできます。

/search/results?keyword="some_keyword",

しかし、結果ページのURLを次のようにすることは可能ですか?

mysite.com/search/results/keyword
4

1 に答える 1

4

私はjQueryを使用します

$('#myform').submit(function(){
    $(this).attr('action', $(this).attr('action') + "/" + $(this).find(input[name="keyword"]).val());
});

もう 1 つの可能性は、コントローラーでプロキシ メソッドを作成することです。URL にすべての投稿値を含めたい場合に便利です。

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

その場合、ポスト データで配列を使用してコードを簡素化します。

<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);
于 2012-08-22T09:37:32.947 に答える