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 , but I can write my own "errors" something likeCodeIgniters
$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.
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_'.
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 ';
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With