2013-01-17 37 views
2

我有一個系統,允許訪客通過列表,排序和過濾瀏覽產品。配置路由器cakephp使無限制/可選參數

我希望我的URL看起來像這樣"/category/smartphones/samsung/android/.../"時選擇「品牌」,「operting系統類型」,「CPU」,...遊客過濾器,這樣他們每次過濾的東西,URL將改變,如:

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

此外,訪問者可以在篩選時進行排序,或者在排序時篩選。所以url可以更像"/category/smartphones/samsung/android/sort:created/direction:desc/"

我不知道cakephp可以做這樣或不是因爲我是初學者在這個框架。或任何類似的解決方案?

我剛剛在路由器中進行了排序配置。但我不知道如何從類似的東西開始(過濾器是無限參數)。

回答

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']$this->params['pass']以獲得您所需的條款。希望有所幫助!