2010-12-13 64 views
0

這裏是我的線路之一...我可以在Kohana 3中使用一個路徑定義嗎?

Route::set('products', 'our-products(/<product>)') 
->defaults(array(
    'controller' => 'products', 
    'action'  => FALSE 
)); 

通過訪問/our-products,你可以得到產品指數(它將調用Controller_Products::action_index())。

我要爲上班路線如下:添加一個可選的產品的時候,應該調用不同的方法,即如果/our-products/product-a請求而不是調用Controller_Products::action_index(),它調用像Controller_Products::action_get('product-a')

我意識到我可以用兩條路線輕鬆完成這項工作,但我寧願用一條路線來完成。

我也雖然關於檢查action_index()內的參數,並調用另一種方法,但聽起來很醜。

我也試過__call()但得到這個非同尋常的錯誤...

Fatal error: Class declarations may not be nested in /home/user/public_html/~new/system/classes/date.php on line 3

是否有可能做我想做什麼?什麼是最好的方法?

感謝

+0

爲什麼你想這樣做,在一個路線?爲了將不同的請求分離到不同的行爲而發明了路由。 – zerkms 2010-12-13 06:59:24

+0

@zerkms他們似乎相關足以進入一條路線。 – alex 2010-12-13 07:08:15

+0

@alex:不同意。如果根據url值有不同的'默認值' - 它們似乎與一個不相關(這是我個人的觀點)。 – zerkms 2010-12-13 07:31:20

回答

0
  1. 檢查product PARAM在action_get()方法,如果空呼籲action_index()(或其他)。
  2. 閱讀this topic關於您的不常見錯誤。
0

超載在Controller::before()方法的動作,就像這樣:

if ($this->request->param('product')) 
{ 
    $this->request->action = 'get'; 
} 
相關問題