Determine the current controller to use for Kohana

What is the best way to determine which controller class is using the Kohana application?

Examples:

  • http://sitesite.com/ - _defaultControllerName_
  • http://somesite.com/frontpage/articles - "frontpage"
  • http://somesite.com/contact/ - "contact"
+3
source share
2 answers

For instances of Kohana 2, the following applies:

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

Now from your application you can get the controller value from the static router class:

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

Documentation

+6
source

Kohana 3.x Request:

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

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


All Articles