I'm using Kohana 3. Does anyone knows why param('controller') result is NULL.
Routing:
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'page',
'action' => 'index',
));
URL: http://localhost/application/page/index/1
Params calls开发者_StackOverflow:
$param = Request::instance()->param('controller');
echo Kohana::debug($param); //results: NULL
$param = Request::instance()->param('action');
echo Kohana::debug($param); //results: NULL
$param = Request::instance()->param('id');
echo Kohana::debug($param); //results: 1
look up in reqeuest.php on line 622:
// These are accessible as public vars and can be overloaded
unset($params['controller'], $params['action'], $params['directory']);
// Params cannot be changed once matched
$this->_params = $params;
that's why line 695 can't return controller
:
public function param($key = NULL, $default = NULL)
{
return $this->_params[$key];
}
this is how you get the controller $controller = Request::instance()->controller;
or $controller = $this->request->controller;
if you inside a controller
For everybody using Kohana 3.1 access the name of the current controller and action like this within a controller:
$this->request->controller()
$this->request->action()
Or if you're not in a controller, you can always access the methods of the current request like this: Request::current()->controller()
See system/classes/kohana/request.php
for more methods you can access similarly.
精彩评论