2013-02-05 37 views
0

我有一個路由查詢字符串的問題。如何在codeigniter搜索中路由查詢字符串?

我正試着用codeigniter進行路由搜索。每個搜索都有一些參數,首先是輸入文本字段,用於標題或描述。其次,我有類似的工具,遊戲,運動......第三,平臺,如IOS,WP,Android ..以及頁面。

我想看到這樣的路線:

/頁/ 3,或

/頁/ 3 /搜索/不管或

/CAT /遊戲或

/貓/遊戲/搜索/ battelfield或

/頁/ 1/CAT /遊戲/搜索/ battelfield或

/搜索/任何或類似的東西。

我使用這個代碼在模型中的功能:

enter code here 

function getAppBy($categ, $page, $str, $platform) { 

    $perpage = 16; 
    $offset = ($page-1)*$perpage; 


    $this->db->select('app.id'); 
    $this->db->from('t_yp_app_category cat, t_yp_user_apps app'); 
    if ($categ != "") { 
     $this->db->where("cat.name =", $categ); 
    } if ($str != "") { 
     $this->db->like('app.yp_title', '%' . $str . '%'); 
     $this->db->like('app.yp_description', '%' . $str . '%'); 
    }if ($platform != "") { 
     $this->db->like('app.yp_platforms', '%' . $platform . '%'); 
    } 

    $this->db->limit($perpage,$offset); 
    $query = $this->db->get(); 
    $result = $query->result_array(); 
    //FIN SELECT 
    if (sizeof($result) > 0) { 
     return $result; 
    } else { 
     return false; 
    } 
} 

enter code here 

謝謝。如果我沒有很好地解釋,讓我知道

回答

1
//www.mysite.com/search/sometitle/puzzle/android/4 
$route['search/(:any)/(:any)/(:any)'] = 'search/getAppby/$1/$2/$3'; //default without offset, which is why offset defaults to 0 
$route['search/(:any)/(:any)/(:any)/(:num)'] = 'search/getAppby/$1/$2/$3/$4'; //default with offset 
//You may want to use some regex rather than wildcards ie:(:any) 

public function getAppBy($input, $category, $platform, $offset=0){} 
+0

如何做的,如果它像本地主機/測試/ 5 /?LAT = 27.6799225&LNG = 85.31890150000004 +查詢= A濾波器=距離 –

+0

@Philip你能回答爲克里希納評論我有同樣的問題。 –