views:

129

answers:

1

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:

$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
+5  A: 

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

antpaw
Thanks a lot! Perfect answer ..
Bob0101

related questions