cakephp反向路由与分页逻辑冲突

发布于 2024-09-18 05:59:23 字数 728 浏览 4 评论 0原文

我有一个新问题:) 我将简要解释我想要实现的目标。现在我有一个看起来像这样的网址。

/products/index/brand:figleaves

我希望它看起来像这样

/brand/figleaves

通过编写以下路由规则我得到了我想要的。

Router::connect('/brand/:brand/*', array('controller' => 'products', 'action' => 'index'));

一切都很顺利,但后来我发现分页逻辑已被破坏。 如果我点击“下一页”,我会被重定向到 URL /products/index/page:2

  1. 它不会传递品牌参数
  2. ,而是重定向回 products_controller,而不是我在路由规则中定义的 url。

事实上,我需要将其作为 url /brand/figleaves/page:2

奇怪的是,如果我浏览到 /products/index/brand:figleaves 并单击“下一步”,然后我会被重定向到 /brand/figleaves/page:2。这该如何解释呢?

我希望得到一些帮助:)

亲切的问候, 洛朗

I've a new question :)
I'll briefly explain what I'm trying to achieve. Right now I have an url that looks like this.

/products/index/brand:figleaves

I want this to look like this

/brand/figleaves

By writing the following route rule I get what I want.

Router::connect('/brand/:brand/*', array('controller' => 'products', 'action' => 'index'));

Everything goes fine, but then I discovered the pagination logic has been destructed.
If I click on 'next page' I get redirected to the url /products/index/page:2.

  1. it doesn't pass the brand parameter
  2. it redirects back to the products_controller and not to the url I defined in the route rule.

In fact I'd need this as url /brand/figleaves/page:2.

Strange thing is if I browse to /products/index/brand:figleaves and click on Next, then I get redirected to /brand/figleaves/page:2. How can this be explained?

I'd appreciate some help with this :)

Kind Regards,
Laurent

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凡间太子 2024-09-25 05:59:23

对于那些对我如何解决这个问题感兴趣的人。

我只是在我看来的分页器中定义了一些选项并显式传递了值,如下所示。

    $this->Paginator->options(array
            ('url'=> array(
                'controller' => 'products', 
                'action' => 'index',
                'brand'=>$this->params['brand']
   )));  

这样就可以完成工作了:)

For those interested in how I solved this.

I just defined some options in the paginator in my view and passed the value explicitly, like this.

    $this->Paginator->options(array
            ('url'=> array(
                'controller' => 'products', 
                'action' => 'index',
                'brand'=>$this->params['brand']
   )));  

That does the job :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文