0

我正在制作博客和 url 路由是这样的-

Router::connect('/blog/c/:catid/*', 
array('controller' => 'blogarticles', 'action' => 'index'));

它适用于 url as-/blog/c/3/other-articles

但是当我在视图中使用分页器时

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

它生成网址为- /blogarticles/index/other-articles/page:2

应该在分页器中进行哪些更改以生成正确的 url。

请提出可能的解决方案,在此先感谢

4

2 回答 2

2

这应该可以解决您的问题:

$this->Paginator->options(
    array(
        'controller' => 'blog',
        'action' => 'c',
        $catid,
        $title
    )
);

诀窍是依次传递 blog 作为控制器和 c 作为动作,以及所有其他变量(不限于 $catid 和 $title)作为附加参数,顺序!

注意:我在这里假设你已经从你的控制器“设置”了 $catid 和 $title,到当前的“类别 id”和“标题”。我还假设您的 URL 始终采用以下格式:/blog/c/:catid/:title

您可能还想查看我对类似问题的回答:https ://stackoverflow.com/a/25097693/2862423

于 2014-08-02T17:47:41.037 回答
0

您想要的是为该视图设置 PaginatorHelper 的选项:

<?php $this->Paginator->options(array('url' => '/blog/c/3/other-articles')); ?>

关于 PaginatorHelper 选项功能的 CakePHP 书籍部分:http: //book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#modifying-the-options-paginatorhelper-uses

于 2013-04-09T07:00:56.463 回答