CodeIgniter Forums

Full Version: Get name of parent method and classf
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, i'm writing a log script which basicaly logs the user actions and stores them in the database for further analysis. Its a very basic script but it does the job. However i need a way to get the name of the parent methon which the log action is called and the class. The standard php get_parent_class returns CI_Controller instead on the class name i want.




For example if i have something like this:




PHP Code:
class MyClass extends CI_Controller {

public function 
MyFunction() {
 
  $this->log->log_actions($data);
}


 i want a way to the the MyClass name and the MyFunction.
You sholdn't use get_called_class ?

or you can declare you MY_Controller class in application/core with some fields like $class_name , ... and user it as parent of your controllers instead of CI_controller, so you can initialize that fields in __construct function for each subClass.
__CLASS__ doesn't work also ???
What about segment(2) for the class name and segment(3) for the method name?
(06-13-2015, 09:03 AM)Wouter60 Wrote: [ -> ]What about segment(2) for the class name and segment(3) for the method name?

That nice idea, but no so if custom route is enabled or routes are remapped.
Pretty much everything you suggested works. I will probably go with the segments Smile