Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter, Know the controller which called function

I am trying to create library that will write "error" messages in database, I do not think that I will be able to write PHPs errors nor CodeIgniters, but I can write my own "errors" something like

$this->error->write("User is not allowed to go in here");

I know there is a error handling already built in CodeIgniter on top of all it only supports writing errors/infos/debugs in file not database.

The real question is: how to get controller that called function.

Lets say I am in controller -> ./admin/settings.php and error ocures, code will call my library and I want it to store controller that called it. (I may be forced to send it as parameter but I don't want to write manually that it was fcn("error text", "/settings.php");

Assumed output: /controllers/admin/settings.php somewhere inside class that is called by controller.

like image 223
Kyslik Avatar asked Jun 07 '13 10:06

Kyslik


People also ask

What is my controller in CodeIgniter?

Codeigniter will automatically load My_Controller as long as it's in your application/core directory. Show activity on this post. You don't need to autoload your class, the framework will do it for you. In your case check the config file whether the subclass_prefix is 'MY_'.

How do I find my default controller in CodeIgniter?

Defining a Default Controller CodeIgniter can be told to load a default controller when a URI is not present, as will be the case when only your site root URL is requested. To specify a default controller, open your application/config/routes. php file and set this variable: $route['default_controller'] = ' Blog ';

How do you call a controller function in CI?

By default Controller always calls index method. If you want a different method, then write it in the Controller's file and specify its name while calling the function. Look at the URL, there is no method name is mentioned. Hence, by default index method is loaded.


1 Answers

You can use the router class to get this info

Also works with Codeigniter v3.0.x

To get the controller(class)

$this->router->class

To get the method(function)

$this->router->method
like image 152
Rooneyl Avatar answered Nov 15 '22 17:11

Rooneyl