Cake PHP 3-在分页器URL中向div id添加书签

时间:2019-07-14 16:55:22

标签: url redirect cakephp paginator

在Cake PHP 3中,如何在分页器URL中向div id添加书签?

保留分页器及其元素的div = {<div id=mydivid">

分页器网址为:http://myweb.tld/?page=2

我需要将其修改为http://myweb.tld/?page=2#mydivid

以便分页器重定向到激活它的同一个div,而不重定向到页面的开头。

谢谢。

1 个答案:

答案 0 :(得分:0)

在视图中创建URL

它在纪录片中:https://book.cakephp.org/3.0/en/views/helpers/url.html#generating-urls

echo $this->Url->build([
    "controller" => "Posts",
    "action" => "search",
    "?" => ["foo" => "bar"],
    "#" => "first",
]);

// Output
/posts/search?foo=bar#first

在控制器中创建URL

纪录片:https://book.cakephp.org/3.0/en/development/routing.html#generating-urls

Router::url([
    'controller' => 'Articles',
    'action' => 'index',
    '?' => ['page' => 1],
    '#' => 'top'
]);

// Will generate a URL like.
/articles/index?page=1#top