如果你想那樣做......
你可能只是做這樣的事情,假設有多個輸入後,他們只對搜索,它可能是這個樣子
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風格網址的使用它們,儘管這是一個小更復雜
其他信息:
如果只有一個搜索輸入字段,並且這些條款之間用空格分隔,那麼您可能希望這樣做(可能有一些正則表達式過濾)...這種替換foreach($_POST as $k => $v)...
循環:如果你希望你的URL是這樣
$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 . '+';
}
}
感謝,我將不得不在這個 – iamjonesy 2011-01-27 12:30:16