我对路由查询字符串有疑问。
我尝试使用codeigniter进行搜索。我为每个搜索都有一些参数,首先是输入文本字段,标题或描述。其次,我有类别,例如,公用事业,游戏,练习......第三,一个平台,如IOS,WP,Android ..以及页面。
我希望看到这样的路线:
/ page / 3,或
/ page / 3 / search / whatever或
/ cat / Games或
/ cat / Games / search / battelfield或
/ page / 1 / cat / games / search / 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
谢谢。如果我没有解释清楚,请告诉我
答案 0 :(得分: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){}