CakePHP 5 Custom Routing Issue with Paginator Links

Hello everyone.
I want to create a custom (SEO-friendly) routing for a multi-language web app.
The original route looks like this: /institutions/category/3/example-entry
I want to add the current language and change it to this: /en/offers/adults/3-example-entry

My route entry in config/routes.php looks like this:

$languages = ['de', 'en', 'fr', 'pl', 'ru', 'tr', 'vi', 'ro', 'ar', 'uk'];
$languages_string = implode('|', $languages);
...
$builder->connect('/{language}/offers/adults/{id}-{slug}', ['controller' => 'Institutions', 'action' => 'category'], ['language' => $languages_string, 'pass' => ['id', 'slug'], 'id'=>'[0-9]+']);

The Html-Link-Helper call looks like this:

<?php echo $this->Html->link($institution->category->title, ['controller' => 'Institutions', 'action' => 'category', 'id' => $entry->id, 'slug' => $entry->slug, 'language' => $language]); ?>

All works fine and the generated routes are good. But when I use the Paginator helper $this->Paginator->numbers() the custom adaptation doesn’t work. Paginator URL looks like this:
/institutions/category/3/example-entry?page=2

How can I achieve an url like this: /en/offers/adults/3-example-entry?page=2 ?

Thanks in advance!
Mathias

Try calling

$this->Paginator->options([
    'url' => [
        'controller' => 'Institutions',
        'action' => 'category',
        'language' => $language,
        'id' => $entry->id,
        'slug' => $entry->slug
    ]
]);

before echo $this->Paginator->numbers();

1 Like

@KevinPfeifer Thanks a lot! Works like charm :slight_smile: