Codeigniter how to get all / specific method in current controller

I know this code:

$this->router->fetch_class(); // get current controller name
$this->router->fetch_method(); // get current method name

What I want to do is get the whole method available in the current controller or specific controller. Has anyone had the same experience? Thank.

SOLUTIONS

I create a helper to list the entire method in a specific controller

function list_this_controllers_method_except($controller, $except = array())
{
    $methods = array();

    foreach(get_class_methods($controller) as $method)
    {
        if (!in_array($method, $except))
        {
            $methods[] = $method;
        }
    }

    return $methods;
}
+4
source share
3 answers

you can use native php to get class methods

get_class_methods($this);

the $ is a controller called

Sample only

class user extends CI_Controller {

    public function __construct() {

                #-------------------------------
                # constructor
                #-------------------------------

                parent::__construct();

                var_dump(get_class_methods($this));

            }

}

read the documentation

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

+4
source

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

, :

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

+1

    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>'; 
} 
0

All Articles