0

The app has some prefixed routes like so:

Router::scope('/ru', function (RouteBuilder $routes) {
    $lang = 2;
    $routes->setRouteClass(DashedRoute::class);
    $routes->connect('/:slug',                          ['controller' => 'Pages', 'action' => 'pages', 'lang' => $lang])->setPass(['slug']);
$routes->fallbacks(DashedRoute::class);
});

Page in question: http://localhost:8765/ru/smi-o-nas where there are some pagination links using this method:

<?= $this->Paginator->numbers() ?>

It generates links including matched controller and action:

http://localhost:8765/ru/pages/pages/smi-o-nas?page=2 

So is it that routes are not set up correctly, or there is an option to make Paginator generate relative links like this:

http://localhost:8765/ru/smi-o-nas?page=2

Looked at the docs, paginator helper code, but all I came up with is setting Paginator config url, which still does no good. Using this:

$this->Paginator->setConfig('options.url', ['controller' => 'ru', 'action' => 'smi-o-nas']);

Simply sticks /ro/smi-o-nas/ in the middle for the link:

http://localhost:8765/ru/ru/smi-o-nas/smi-o-nas?page=2

So do I need to set up routes in a different way, or is there an option for relative urls?

Update I figured out that a relative url would not work for paginator as it will result in urls like "localhost:8765/ru/ru/smi-o-nas/smi-o-nas?page=2?page=3"

Dodgy solution

<?php for($page_number = 1; $page_number <= $this->Paginator->counter("{{pages}}"); $page_number ++):?>
    <?php if ($page_number == $this->Paginator->counter("{{page}}")): ?>
        <span><?= $page_number ?></span>
    <?php else : ?>
        <a href="<?= $this->Url->build($this->request->here) ?>?page=<?= $page_number ?>"><?= $page_number ?></a>
    <?php endif ; ?>
<?php endfor; ?>
Yevgeniy
  • 300
  • 2
  • 7
  • What is the link you are expecting Paginator to generate? – cnizzardini Jan 10 '20 at 01:31
  • link to the current page + pagination, well not exactly current page, rather base page if we are already on page 2 in pagination. Like so: 1. when no pagination is selected: http://localhost:8765/ru/ru/smi-o-nas/smi-o-nas?page=2 2. when page 2 is selected: http://localhost:8765/ru/ru/smi-o-nas/smi-o-nas?page=1 – Yevgeniy Jan 10 '20 at 08:43
  • 1
    So you expect this `localhost:8765/ru/ru/smi-o-nas/smi-o-nas?page=2` but you actual get this `http://localhost:8765/ru/pages/pages/smi-o-nas?page=2` is that the crux of the problem? – cnizzardini Jan 10 '20 at 12:55
  • Did you try something like this https://stackoverflow.com/questions/39871520/cakephp-3-custom-route-in-pagination or search for things like "cakephp paginator use routes" if not, i will try in my cake app to reproduce and solve your issue when i get home later. – cnizzardini Jan 10 '20 at 13:02

0 Answers0