bramus / bramus/router

Get parameters in mount function

Open
#75 3 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
PHP
Stars
1.1k
Forks
236
PR merge metrics
No merged PRs in 30d

Description

My domains are structured like this to server different language versions of the same page:
`example.com/nl/page-1` and `example.com/en/page-1` for the same url in different languages.

My code looks like this:
```
$router->mount('/(\w+)', function($lang) use ($router){ // wrap in lang-var
echo $lang;

$router->get('/page-1', function() {
// code
});

$router->get('/page-2', function() {
// code
});
});
```

But it gives me the following error:
`Warning: Missing argument 1 for {closure}() in [path]/routes.php on line 13`

Is there a way to get the baseroute in a variable here?

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the warning using the routes.php example from the issue, then trace how mount invokes its callback and how nested get routes are registered. Check whether the language value can be passed through that flow, and consider the issue complete when the shown routes can access the language parameter without the missing-argument warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.