Welcome Guest, Not a member yet? Register   Sign In
Gettin the actions list from a controller
#1

[eluser]Garf Orlock[/eluser]
Hi, first of thanks for reading this post.

I need to get a list of controller/actions, so what I got is the following:

Code:
$modulos = array();

foreach(glob(APPPATH . '/modules/*') as $modulo)
{
    $modulo = basename($modulo);
    $modulos[] = $modulo;            
}
and as expected I get an array of controllers.

Code:
Array
(
    [0] => login
    [1] => mensaje
    [2] => recurso
    [3] => role
    [4] => usuario
    [5] => welcome
)

Now what I need to get is an array of the actions in the controller. I was thinking of reading the file into a var an then doing a grep for

Code:
function actionname

then remove the function word and load into an array what is left. But I am not 100% sure about this method

Any one of you has faced this challenge before, any clues ideas of how I could get this task done?

Thanks again for reading this post.
#2

[eluser]Dyllon[/eluser]
PHP has great documentation.

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

[eluser]Garf Orlock[/eluser]
@Dyllon thanks for the hint.

Just in case anyone needs it, this is what I came up with
Code:
$modulos = array();
foreach(glob(APPPATH . '/modules/*') as $modulo)
{
    $modulo = basename($modulo);
    $modulos[] = $modulo;
            
    include_once(APPPATH.'modules/'.$modulo.'/controllers/'.$modulo.'.php');
}    
        
$i=0;
foreach ($modulos as $modulo)        
{
    echo( $modulos[$i]);
    echo "<pre>";        
    print_r( get_class_methods($modulos[$i]));
    echo "</pre>";
    $i++;      
}




Theme © iAndrew 2016 - Forum software by © MyBB