如果你想那样做...
你可以做这样的事情,假设有多个帖子输入并且它们只用于搜索,它可能看起来像这样
function search(){
$url = $this->uri->segment(2);
if(empty($url)){
if((isset($_POST) && (!empty($_POST))
{
$search_seg = '';
foreach($_POST as $k => $v){
// I always make sure to use the CI post w/
// TRUE set in the second param so as to XSS filter the user input
$var = $this->input->post($k, TRUE);
// Just incase the user input had a plus in it?
$var = str_replace('+', '%20', $var)
// Concatenate the search string
$search_seg .= $var . '+';
}
// Make the url, use substr() to strip the last + off the end
$search_seg = 'search/' . substr($search_seg, 0, -1);
/* Make sure CI's URL helper is enabled
$this->load->helper('url'); if it hasn't been loaded
This will give the illusion that the form post went to this URL,
thus doing what you're looking for... */
redirect($search_seg, 'location');
}else{
// There was no post, do whatever
}
}else{
$search_arr = explode('+', $url);
}
上面应该几乎完全按照您的描述进行,尽管有一些方法可以重新创建 $_GET 数组并仍然将它们与 CI 样式 URL 一起使用,尽管这有点复杂
附加信息:
如果只有一个搜索输入字段,并且例如,这些术语由空格分隔,那么您可能想要这样做(可能有一些正则表达式过滤)......foreach($_POST as $k => $v)...
用这个替换循环:
$keywordinput = $this->input->post('keywords', TRUE);
$keywordinput = trim($keywordinput);
$keywords = explode(' ', $keywordinput);
foreach($keywords as $word){
if(!empty($word)){
$word = str_replace('+', '%20', $var)
$search_seg .= $word . '+';
}
}