PHP Slim获取变量

PHP Slim获取变量,php,slim,Php,Slim,我有一个搜索页面。我希望Slim从URL获取参数,如下所示: mywebsite.com/search/search category/search strings/min price/max price 例如: mywebsite.com/search/laptops/asus/500/2000 这可以通过以下代码完成: $app->get('/:type/:str/:minprice/:maxprice', function ($type,$str,$minprice,$maxpric

我有一个搜索页面。我希望Slim从URL获取参数,如下所示:
mywebsite.com/search/search category/search strings/min price/max price
例如:
mywebsite.com/search/laptops/asus/500/2000

这可以通过以下代码完成:

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

});
但问题是,如果我导航到:
mywebsite.com/search/laptops/asus
。 它给了我404错误,把整个页面弄得一团糟,但我希望它只显示标题中有“华硕”字样的笔记本电脑

我怎样才能做到这一点? 我希望Slim获得参数列表,并按如下方式解析它们:

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.

Slim允许可选参数: