2013-07-11 85 views
0

使用Kohana 3.3,我創建了一個選項卡式界面,我試圖根據路由參數來檢測哪個選項卡處於活動狀態。獲取控制器路由參數

測試與2個網址看起來像這樣:mysite.com/p/mycontroll 和:mysite.com/p/Francis-Lewis/mycontroll

我的路線是這樣的:

Route::set('profile', 'p(/<name>)(/<controller>(/<action>))', array(
     'name'   => '[\w\-]+', 
     'controller' => '[a-z]+', 
     'action'  => '(view|edit|save|delete|create|cancel)', 
    ))->defaults(array(
     'name'   => null, 
     'directory'  => 'profile', 
     'controller' => 'main', 
     'action'  => 'index', 
    )); 

路線本身工作正常,選擇mycontroll控制器。 這裏是哪裏出了問題進來 在控制器:

$this->request->param('controller'); // returns NULL 

在視圖

<?= Request::current()->param('controller') ?> // returns NULL 

周圍敲打我的頭一段時間後,我加入到Kohana的Request類的函數返回$_params數組看看裏面有什麼。

這裏的一切,它返回:

name => 'Francis Lewis' 

任何想法如何獲得當前控制器?

回答

1

請求對象沒有爲一個功能:

$this->request->controller(); // Returns the current controller as a String 
0

如果你有絕對的把握要初步控制,那麼你可以使用下一個方法:

Request::initial()->controller(); 

否則使用此方法:

Request::current()->controller();