Sampson
Sampson

Reputation: 268334

Determine Current Controller in Use for Kohana

What is the best way to determine which Controller class a Kohana application is presently using?

Examples:

Upvotes: 3

Views: 1308

Answers (2)

laurent
laurent

Reputation: 90746

For Kohana 3.x, you need to get the current controller from the Request object:

echo Request::$current->controller();

Upvotes: 5

Sampson
Sampson

Reputation: 268334

The following applies to Kohana 2 instances...

You can do this by using the Router library. By default, this library is located in /system/libraries/Router.php - go ahead and copy it into /application/libraries as is the standard practice for all libraries being used.

Now, from within your application you can get the controller value from the static Router class:

print Router::$controller; // outputs current Controller

Documentation

Upvotes: 6

Related Questions