The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

Default value in Slim 3 Route

dewey992's Avatar


18 Jan, 2016 06:39 PM

How to set default value when routing in Slim 3? I've been looking for this issue in Fast Route github but unfortunately no result.
I'm not going to code $args['optional_param'] = isset($args['optional_param']) ? $args['optional_param'] : 'default_value'; since the Slim 2 version was much more preferable with function($optional_param = 'default_value') {}

Is there any way around?

  1. Support Staff 1 Posted by Andrew Smith on 19 Jan, 2016 01:59 PM

    Andrew Smith's Avatar

    You can do this by using the Request object instead.

    $app->get('/{id}', function ($req, $res) {
        $id = $req->getAttribute('id', 'defaultValue');
  2. 2 Posted by dewey992 on 19 Jan, 2016 02:16 PM

    dewey992's Avatar

    Wow this works! Thank you!

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? 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