簡體   English   中英

我可以在Kohana 3的控制器的before()方法中獲得操作嗎?

[英]Can I get the action in the before() method of a controller in Kohana 3?

我的控制器有......

class Controller_Staff extends Controller {

    public function before() {
       parent::before();
       $id = $this->request->param('id');
       $action = $this->request->param('action');
    }

    public function action_get($id) {
       var_dump($id);
    }

}

我的路線是......

Route::set('a', 'bla/<action>/<id>',
            array('id' => '\d+', 'action' => '(get|set)'))
    ->defaults(array(
        'controller' => 'staff',
        'action' => 'set'
    ));

當我輸入一個調用Controller_Staff->before() (在調用action_get() Controller_Staff->before()的URL( bla/get/42 )時,可以在before()訪問$id ,但是$action始終為NULL

有沒有更好的方法來訪問before()方法中的當前$action

謝謝。

找到了!

結果容易。

$action = $this->request->action;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM