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

Get parameters in mount function #75

Open
Duncank opened this issue Aug 15, 2018 · 3 comments
Open

Get parameters in mount function #75

Duncank opened this issue Aug 15, 2018 · 3 comments

Comments

@Duncank
Copy link

Duncank commented Aug 15, 2018

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?

@abmmhasan
Copy link

abmmhasan commented Sep 5, 2018

Ya, this router only accepts static options in mount(). Doesn't support regex. It needs improvement.

@artyuum
Copy link
Contributor

artyuum commented Dec 15, 2018

Here is what you can do instead :

$router->mount('/(\w+)', function() use ($router) {

    $router->get('/(\w+)', function($lang, $page) {

        dump($lang, $page);

    });

});

$router->run();

URL: /en/account
capture

@bramus
Copy link
Owner

bramus commented Jan 25, 2019

Please check the included multilang demo files, as they provide what you're willing to do.

As for mount() itself: I'll gladly accept a PR that provides this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants