Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Placeholder Token Matching on optional token #162

Closed
bkdotcom opened this issue Sep 21, 2018 · 0 comments
Closed

Custom Placeholder Token Matching on optional token #162

bkdotcom opened this issue Sep 21, 2018 · 0 comments

Comments

@bkdotcom
Copy link
Contributor

bkdotcom commented Sep 21, 2018

https://github.com/auraphp/Aura.Router/blob/3.x/docs/defining-routes.md#custom-placeholder-token-matching

tweaking the supplied example so that date is optional (and even supplying a default date)

<?php
$map->get('/calendar{/date}')
    ->tokens([
        'date' => function ($date, $route, $request) {
            try {
                new \DateTime($date);
                return true;
            } catch(\Exception $e) {
                return false;
            }
        }
    ])
    ->defaults(['date'=>'yesterday']);

will throw a notice: vendor/aura/router/src/Rule/Path.php (line 89): = Undefined index: date

notice is thrown even when supplying a default date value.

NaokiTsuchiya pushed a commit to NaokiTsuchiya/Aura.Router that referenced this issue Jan 29, 2022
NaokiTsuchiya added a commit to NaokiTsuchiya/Aura.Router that referenced this issue Jan 29, 2022
harikt added a commit that referenced this issue Jan 29, 2022
@harikt harikt closed this as completed in 038abcc Jan 29, 2022
harikt added a commit that referenced this issue Jan 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant