2015-09-10 91 views
0

我有一個搜索頁面。我希望Slim從下面的URL中獲取參數: mywebsite.com/search/search-category/search-strings/min-price/max-price 例如: mywebsite.com/search/laptops/asus/500/2000PHP Slim獲取變量

這可以通過這個代碼來完成:

$app->get('/:type/:str/:minprice/:maxprice', function ($type,$str,$minprice,$maxprice) { 

}); 

但問題是,如果我定位到:mywebsite.com/search/laptops/asus。 它給了我404錯誤和整個頁面混亂,但我希望它只顯示其標題中的「華碩」的筆記本電腦。

我該如何做到這一點? 我想修身獲得的參數列表,並分析它們象下面這樣:

if there is no parameter, then show all products (mywebsite.com/search/). 
--------------------------------------- 
if only one parameter is present, then it's category (mywebsite.com/search/laptops). 
--------------------------------------- 
if 2 parameters are present, then the first one is category and the second one is keyword (mywebsite.com/search/laptops/apple/). 
--------------------------------------- 
and so on the 3rd one is minprice and the 4th one is maxprice. 

回答