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

URI Mixed Parameters (Optional and Fixed)

kishore's Avatar

kishore

19 Apr, 2012 07:33 PM

How should I handle this route path?

    // This is fine. I can check if each parameter is supplied.
     $app->get("/accounts/(:id/(:s_date/(:e_date/)))', 'show_accounts')

How do we handle / know the fixed and optional route like below.
Specifically how do I know if '/registered/' is used in the URI

     $app->get("/accounts/(:id/)/registered/(:attended/)/getcount/ ', 'show_accounts')

Is there a specified way to handle this one or I need to handle it by checking the URI?

Any help?

  1. Support Staff 1 Posted by Josh Lockhart on 19 Apr, 2012 07:49 PM

    Josh Lockhart's Avatar

    I think you're over-complicating it. I'd separate your logic into these separate routes:

    • /accounts/:id/registered
    • /accounts/:id/attended

    And so on. Otherwise it just gets confusing and unwieldy.

  2. 2 Posted by kishore on 19 Apr, 2012 08:34 PM

    kishore's Avatar

    Thanks, Josh!

    But even in this case, how do I verify the path?

     /accounts/:id/registered
     /accounts/:id/attended
    

    I can verify the ":id" as a parameter. But /registered, /attended. How do I check these in the call back function.

  3. Support Staff 3 Posted by Josh Lockhart on 19 Apr, 2012 08:37 PM

    Josh Lockhart's Avatar

    If you separate them into separate routes, the fact that a given route is run would be your verification.

  4. 4 Posted by kishore on 19 Apr, 2012 09:06 PM

    kishore's Avatar

    @Josh. As simple as that! :-) Awesome. Thanks!

  5. 5 Posted by kishore on 20 Apr, 2012 06:45 PM

    kishore's Avatar

    Josh,

    Got bumped. Need your help here..
    Here are my two routes:

     $app->get('/Kents/(:id/(:s_date/(:e_date/)))', 'get_eves');
     $app->get('/Kents/:id/:e_id/Candidates/(:status/)', 'get_stats');
    

    When I call:

     /Kents/:id/:e_id/Candidates/
    

    Do you think it should call the 2nd one? Its calling the first one. Not sure if I am missing anything here.

  6. 6 Posted by kishore on 20 Apr, 2012 07:28 PM

    kishore's Avatar

    Anyways, I couldn't get above working. However, you have built a nice "very forward thinking" method called "pass()". I used this to get this working without much code changes.

    Awesome!

  7. Andrew Smith closed this discussion on 08 Aug, 2012 09:52 AM.

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