0

我用前缀设置了路由admin,我遇到问题的页面有这个路径:

http://mydomain.com/admin/posts

我希望这是一个分页的博客文章列表。该 URL 调用admin_index我的posts控制器中的操作。很简单。

在我的观点的底部,我有这个:

<?php echo $this->Paginator->numbers(array('first' => 1, 'last' => 1, 'separator' => '')); ?>

但是,分页链接将我发送到一个不存在的 URL:

http://mydomain.com/posts/admin_index/page:2

我需要它来生成一个链接,例如:

http://mydomain.com/admin/posts/2

我怎样才能做到这一点?我已经尝试像这样设置我的分页器选项:

<?php $this->Paginator->options(array(
    'url'=> array('controller' => 'posts',
    'action' => 'index',
    'prefix' => 'admin'
))); ?>

但这会使 URL 像这样:

http://mydomain.com/posts/index/prefix:admin/page:2

我怎样才能让它工作?

4

1 回答 1

1

请阅读文档中有关前缀路由的部分:http: //book.cakephp.org/2.0/en/development/routing.html#prefix-routing

特别是你需要告诉 cake 你想在你的应用程序中使用哪些路由的部分:

Configure::write('Routing.prefixes', array('admin'));

然后您的路由将在您的分页中起作用。

于 2013-06-26T23:34:23.167 回答