【问题标题】:Configure the routers cakephp to make unlimited/optional parameters配置路由器 cakephp 以制作无限/可选参数
【发布时间】:2023-03-10 13:14:01
【问题描述】:

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

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

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 能不能做这样的事情,因为我是这个框架的初学者。或任何类似的解决方案?

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

【问题讨论】:

    标签: cakephp parameters routing


    【解决方案1】:

    这实际上很简单,如果您对 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']$this->params['pass'] 即可获得所需的条款。希望对您有所帮助!

    【讨论】:

      猜你喜欢
      • 2011-12-19
      • 2016-10-12
      • 2011-01-09
      • 1970-01-01
      • 2012-03-27
      • 1970-01-01
      • 2011-03-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多