2

我有一个系统允许访问者通过列出、排序和过滤来浏览产品。

当访问者通过选择“品牌”、“操作系统类型”、“cpu”等进行过滤时,我希望我的 url 看起来像这样"/category/smartphones/samsung/android/.../",所以他们过滤的每一件事,url 都会改变如下:

filter by brand : /category/smartphones/samsung/
by os type : /category/smartphones/android/
by brand and os type : /category/smartphones/samsung/android/
...

此外,访问者可以在筛选时进行排序,也可以在排序时进行筛选。所以网址可以更像"/category/smartphones/samsung/android/sort:created/direction:desc/"

我不知道 cakephp 能不能做这样的事情,因为我是这个框架的初学者。或任何类似的解决方案?

我刚刚完成了路由器中的排序配置。但我不知道如何从这样的事情开始(过滤器是无限参数)。

4

1 回答 1

4

这实际上很简单,如果您对 Cake 的默认路由方法感到满意,您甚至不需要在路由文件中添加条目。:-)

这就是我所做的...

class PagesController extends AppController {
    function test() {
        debug($this->params['named']);
        debug($this->params['pass']);
    }
}

然后我打电话...http://localhost/pages/test/x/y/z/something:x/else:y/1/2/3

它输出这个...

array(
    'something' => 'x',
    'else' => 'y'
)

array(
    (int) 0 => 'x',
    (int) 1 => 'y',
    (int) 2 => 'z',
    (int) 3 => '1',
    (int) 4 => '2',
    (int) 5 => '3'
)

因此,您只需使用$this->params['named']and$this->params['pass']即可获得所需的条款。希望有帮助!

于 2013-01-23T04:57:25.243 回答