Codeigniter how to get all/specific method in current controller Codeigniter how to get all/specific method in current controller codeigniter codeigniter

Codeigniter how to get all/specific method in current controller


you can use native php to get the class methods

get_class_methods($this);

the $this is the controller being called

Sample only

class user extends CI_Controller {    public function __construct() {                #-------------------------------                # constructor                #-------------------------------                parent::__construct();                var_dump(get_class_methods($this));            }}

read on the documentation

http://php.net/manual/en/function.get-class-methods.php


-Oli Soproni B.(https://stackoverflow.com/users/1944946/oli-soproni-b)

Thanks I have used it like this:

class user extends CI_Controller {    public function __construct() {                #-------------------------------                # constructor                #-------------------------------                parent::__construct();                $methodList = get_class_methods($this);                foreach ($methodList as $key => $value) {                 if($value!="__construct"&&$value!="get_instance"&&$value!="index") {            echo "$value"."\n";                 }                }            }}

junior


Try This test function in controller

    public function test()    {        $this->load->helper('file');     $controllers = get_filenames( APPPATH . 'controllers/' );     foreach( $controllers as $k => $v )    {        if( strpos( $v, '.php' ) === FALSE)        {            unset( $controllers[$k] );        }    }    echo '<ul>';    foreach( $controllers as $controller )    {        echo '<li>' . $controller . '<ul>';        include_once APPPATH . 'controllers/' . $controller;        $methods = get_class_methods( str_replace( '.php', '', $controller ) );        foreach( $methods as $method )        {            echo '<li>' . $method . '</li>';        }        echo '</ul></li>';    }    echo '</ul>'; }