1

For my Codeigniter (v 3.1.7) project, i create debug menu (like prestashop) with all informations of the login user, error of the page... to debug quickly the page.

So, i want to call the name of the controller and the name of the function. If i'm on the page "login" i want to display:

Controller: Account
Function: Login

I find on this post i tips for my problem but we use Url REWRITING and the name of the url is not the real name of the controller.

creyD
  • 1,972
  • 3
  • 26
  • 55
TiboK
  • 95
  • 3
  • 12
  • What about the `__CLASS__` php keyword? `echo __CLASS__; //MyController` – Kyrre Jan 22 '18 at 10:36
  • Take look at `route.php` which place in `application/config` all routes defined there – Abdulla Nilam Jan 22 '18 at 10:40
  • Possible duplicate of [How to get Controller, Action, URL informations with CodeIgniter](https://stackoverflow.com/questions/2062086/how-to-get-controller-action-url-informations-with-codeigniter) – miradexxx Jan 22 '18 at 15:39

2 Answers2

3

If your CI version is below 3, you have to use like that:

$this->router->fetch_class();
$this->router->fetch_method();

and if your CI version is 3 or above. These methods are deprecated.

$this->router->fetch_class();
$this->router->fetch_method();

You can access the properties instead.

$this->router->class;
$this->router->method;

See codeigniter user guide

URI Routing methods fetch_directory(), fetch_class(), fetch_method() With properties CI_Router::$directory, CI_Router::$class and CI_Router::$method being public and their respective fetch_*() no longer doing anything else to just return the properties - it doesn’t make sense to keep them.

Those are all internal, undocumented methods, but we’ve opted to deprecate them for now in order to maintain backwards-compatibility just in case. If some of you have utilized them, then you can now just access the properties instead:

$this->router->directory;
$this->router->class;
$this->router->method;
Anand Pandey
  • 2,025
  • 3
  • 20
  • 39
2

You could use the URI Class to get that information:

$this->uri->segment(n); // n=1 for controller, n=2 for method, etc
Dave Clarke
  • 2,677
  • 4
  • 22
  • 35