2012-02-08 88 views
2

我有一個路線:的Kohana 3.2路線:多個目錄

Route::set('foo/subdir', '<directory>/<variable>/subdir/<controller>/<action>'); 

我想路線這個網址下面的控制器/動作:

/application/classes/<directory>/subdir/<controller>.php::action_<action>() 

我已經有了,需要這條路線太,這使事情變得複雜:

Route::set('foo', '<controller>/<variable>/<action>'); 

這可能嗎?

回答

0

我想的子目錄追加到目錄

這將使用新的Route::filter功能可以在Kohana的V3.3。 Kohana 3.1或3.2目前沒有辦法在不修改Route和/或Request類的情況下做到這一點。

+1

我最終修改了請求類以添加該功能。 – 2012-11-20 19:36:14

+0

有人可以發表一個如何讓這個工作的例子嗎?它不完全像Kohana文檔解釋很多。 – 2015-02-08 00:49:38

3

爲什麼不能,只要在之後定義了默認路由即目錄路由。

Route::set('foo/subdir', '<directory>/<variable>/subdir/<controller>/<action>') 
    ->defaults(array(
     'directory'  => 'default_directory', 
     'controller' => 'index', 
     'variable'  => 'default_variable', 
     'action'  => 'index', 
    )); 

Kohanas路由支持目錄'本地',沒有必要破解任何東西。

請注意您的類名也必須包含目錄名稱。

+1

是什麼造成的問題是subdir。我想將subdir追加到目錄。你上面的代碼不會去我在第二個代碼片段中指定的目錄。 – 2012-02-08 18:31:50

0

使用REGEXP將目錄和子目錄作爲/ directory /子目錄/控制器/動作 以匹配Route,如// regexp允許您放入/在目錄中。然後在Route類中稍作修改,將其全部更改爲_

尚未測試...。 ;)但我即將...

+3

也許你應該在發佈之前測試... – 2012-10-09 10:41:23