Prusprus
Prusprus

Reputation: 8055

Retrieving request parameters (such as controller and action) in Kohana 3.2

I have my controllers with the following extensions:

Controller_Login extends Controller_Layout Controller_Layout extends Controller_Template

so that all controllers (processing user urls) will pass through Controller_Layout. In my controller_Layout, I'm trying to retrieve the controller and action url values in order to bind them and display them in my layout view.

Calling this echo $this->request->param('controller'); returns nothing (empty string), while calling echo $this->request->param(); return an empty array. Clearly nothing is found in the request.

I'm wondering if this is because I'm trying to retrieve the request values from the parent controller of where the request is actually handled. Idealy i'd like to handle this through my parent controller (controller_Layout) since every page request will need to make this call to retrieve the controller and action value

Any ideas?

Upvotes: 0

Views: 468

Answers (1)

Kemo
Kemo

Reputation: 7042

To get the current Requests controller name, use $this->request->controller() instead of $this->request->param('controller'). Same goes for current action, they aren't variable parameters so they're accessed this way.

And yes, you can handle those in the parent controller, keep it DRY :)

Upvotes: 2

Related Questions