Reputation: 95
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.
Upvotes: 1
Views: 3243
Reputation: 2025
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;
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;
Upvotes: 3
Reputation: 2696
You could use the URI Class to get that information:
$this->uri->segment(n); // n=1 for controller, n=2 for method, etc
Upvotes: 2