Kohana 3 get current controller/action/arguments

前端 未结 3 1978
悲&欢浪女
悲&欢浪女 2021-02-02 13:18

In Kohana 2 you could easily get that information like this:

echo router::$controller;
echo router::$method;
echo router::$arguments[0-x];

Any

3条回答
  •  广开言路
    2021-02-02 14:05

    From inside a controller:

    $this->request->controller

    $this->request->action

    $this->request->param('paramname')

    Unlike K2 arguments in K3 are accessed via kays which you define in your routes.

    Take for example this url:

    Route::set('default', '((/(/)))')    
        ->defaults(array('controller' => 'welcome', 'action' => 'index')); 
    

    To access the "id" argument you'd call

    $this->request->param('id')

    You can't access the controller / action arguments from the param() method.

    Note, you can also use Request::instance() to get the global (or "master") request instance.

    For more information see the K3 guide

提交回复
热议问题