The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

Can I have a GET request with variable number of parameters in the url?

ywndaniel's Avatar

ywndaniel

08 Jun, 2012 08:42 AM

Can I do something like this?
Slim Version: 1.6.0
For example:
http://www.thisismypage.com/api/getitems/seafood/fruit
(will give me items categorized with 'seafood' or 'fruit')

http://www.thisismypage.com/api/getitems/meat
(will give me items categorized with 'meat')

http://www.thisismypage.com/api/getitems/petfood/fruit
(will give me items categorized with 'petfood' or 'fruit')

  1. Support Staff 1 Posted by Andrew Smith on 08 Jun, 2012 09:59 AM

    Andrew Smith's Avatar

    This can be done, its all down to your coding you can pass optional params to Slim it would be down to you how the logic of this works.

  2. 2 Posted by ywndaniel on 08 Jun, 2012 12:42 PM

    ywndaniel's Avatar

    Even the number of criteria is unknown?

    http://www.thisismypage.com/api/getitems/(petfood/fruit) << now 2 criteria
    It can be 1, 2, ... 100, ..., 1000 criterias

    I got 404 Page Not Found when I do this
    http://www.thisismypage.com/api/test/aaa/bbb/ccc

    $app->get('/test/:qwe(/:asd)', 'qweqwe');
    function qweqwe($qwe, $asd=null){
        var_dump($qwe);
        var_dump($asd);
    }
    
  3. Support Staff 3 Posted by Andrew Smith on 08 Jun, 2012 12:49 PM

    Andrew Smith's Avatar

    I spoke to Josh and wildcard catchall routes won't be available until 1.7, so currently you will have to think of another option.

    You would get an 404 not found since you are passing 3 params and Slim is looking for max 2 params.

  4. Support Staff 4 Posted by Brian Nesbitt on 18 Jun, 2012 04:11 PM

    Brian Nesbitt's Avatar

    This is actually possible using route conditions and route middleware to perform the parsing.

    I blogged about it here:
    http://nesbot.com/2012/6/18/slim-wildcard-routes-via-route-middleware

  5. 5 Posted by ywndaniel on 18 Jun, 2012 11:24 PM

    ywndaniel's Avatar

    super detail and useful!!
    thank you very much!!

  6. Brian Nesbitt closed this discussion on 29 Jun, 2012 01:16 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac