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

How to set I18n route with prefix ? #34

Closed
Gransfall opened this issue Aug 21, 2018 · 2 comments
Closed

How to set I18n route with prefix ? #34

Gransfall opened this issue Aug 21, 2018 · 2 comments
Labels

Comments

@Gransfall
Copy link

Gransfall commented Aug 21, 2018

Hello,

I don't undestand how to do I18n Route when i have a prefix

When i try this

 Router::prefix('opn', function ($routes) {
        $routes->fallbacks(\ADmad\I18n\Routing\Route\I18nRoute::class);
    });

I've got Url like this ---> http://xxx.com/fr/opn/users/token so it's good in my mind
but "Opn" is consider as a controller and not as prefix.

Same issue if i do stuff like this :

 Router::prefix('opn', function ($routes) {
        $routes->connect(
            '/:controller',
            ['action' => 'index'],
            ['routeClass' => 'ADmad/I18n.I18nRoute']
        );
        $routes->connect(
            '/:controller/:action/*',
            [],
            ['routeClass' => 'ADmad/I18n.I18nRoute']
        );
    });

Could you help me please with this ?

Best Regards,

@JeanValJeann
Copy link

JeanValJeann commented Oct 21, 2018

Hi,

I got the same one probleme when trying to use plugin within prefix.
I written fallback and add my routes for my prefix but all page aren't accessibles.
Cakephp want a Controller as prefix name.

`
Router::prefix('dashboard', function ($routes) {

// Plugin do not work within prefix
// Plugin wants a controller named as prefix

$routes->connect('/', ['controller' => 'Articles', 'action' => 'index'], ['routeClass' => 'ADmad/I18n.I18nRoute']);
$routes->connect('/', ['controller' => 'Articles', 'action' => 'index']);

// All routes here will be prefixed with `/admin`
// And have the prefix => admin route element added.
$routes->fallbacks('ADmad/I18n.I18nRoute');
$routes->fallbacks('DashedRoute');

});
`

@ADmad
Copy link
Owner

ADmad commented Oct 21, 2018

Router::prefix() and Router::plugin() are just shortcuts for scoping.

So using Router::prefix('opn', ...) you will end up with connected routes of style /opn/:lang/foo/bar not /:lang/opn/foo/bar as you expect. Same for Router::plugin().

So don't use those methods and directly connect required routes using $routes->connect() withing '/' scope.

FYI you can use bin/cake routes on command line to see all connected routes.

@ADmad ADmad closed this as completed Oct 21, 2018
@ADmad ADmad added the question label Oct 21, 2018
@smarek smarek mentioned this issue Sep 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants