views:

243

answers:

1

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

Examples:

  • http://sitesite.com/ - _defaultControllerName_
  • http://somesite.com/frontpage/articles - "frontpage"
  • http://somesite.com/contact/ - "contact"
+5  A: 

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
Jonathan Sampson
Just found this out for myself - thought I'd share for anybody coming across it in the future.
Jonathan Sampson
Small world. I just googled this. Thanks :)
MiseryIndex