Kohana param () not working

I am using Kohana 3. Does anyone know why the result of param ('controller') is NULL.

Routing:

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

URL: http://localhost/application/page/index/1

Params causes:

 $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 
+4
source share
2 answers

look for line 622 in reqeuest.php:

 // 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; 

why line 695 cannot return controller :

 public function param($key = NULL, $default = NULL) { return $this->_params[$key]; } 

so you get the controller $controller = Request::instance()->controller; or $controller = $this->request->controller; if you are inside the controller

+6
source

For everyone who uses Kohana 3.1, access to the name of the current controller and action, as it happens in the controller:

$this->request->controller()

$this->request->action()

Or, if you are not in the controller, you can always access the methods of the current request as follows: Request::current()->controller()

See system/classes/kohana/request.php for more methods that you can access in the same way.

+3
source

Source: https://habr.com/ru/post/1316123/


All Articles