CodeIgniter Forums
Get name of parent method and classf - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Get name of parent method and classf (/thread-62144.html)



Get name of parent method and classf - FlevasGR - 06-13-2015

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.


RE: Get name of parent method and classf - nasser.man - 06-13-2015

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.


RE: Get name of parent method and classf - Blair2004 - 06-13-2015

__CLASS__ doesn't work also ???


RE: Get name of parent method and classf - Wouter60 - 06-13-2015

What about segment(2) for the class name and segment(3) for the method name?


RE: Get name of parent method and classf - Blair2004 - 06-13-2015

(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.


RE: Get name of parent method and classf - FlevasGR - 06-14-2015

Pretty much everything you suggested works. I will probably go with the segments Smile