EllisLab text mark
Advanced Search
     
Display all controller and method
Posted: 24 June 2010 04:45 PM   [ Ignore ]
Joined: 2010-06-10
8 posts

Hi,
is it possible to display all the controller and method I have created so far?
i hate to have to go through folder and file to find out where i have created my application.

 
Posted: 24 June 2010 11:15 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2009-11-12
80 posts

Codeigniter cant do that. but your PHP Editor (like aptana, dreamweaver) can help you to navigate your files easily.

 Signature 

tourdavao.com

 
Posted: 25 June 2010 12:26 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2010-06-10
8 posts

No you got me wrong there.
what i meant was like if i go to my site example.com/ci/index.php
i want it to show like /index/

controller
-class
—function
—function
—function
-anotherclass
—function
—function

with links

 
Posted: 25 June 2010 01:48 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2009-09-15
53 posts

- Go through your controllers folder with scandir(), to get a list of the classes.
- Include each controller file.
- For each controller class, use the get_class_methods() function to get a list of their methods.

 Signature 

CodeIgniter tutorials and more:

http://www.phpandstuff.com

CodeIgniter and Doctrine from scratch:

Day 1 - Day 2 - Day 3 - Day 4

 
Posted: 14 January 2012 11:21 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2011-10-08
5 posts

I know this is old, but I wanted to do this tonight and stumbled upon this thread.  This code worked for me (basically an implementation of the steps suggested by Burak):

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Controllers extends CI_Controller {

    
function __construct()
    
{
        parent
::__construct();
    
}

    
public function index()
    
{
        $controllers    
= array();

        
$dir            APPPATH.'/controllers/';
        
$files          scandir($dir);

        
$controller_files array_filter($files, function($filename{
            
return (substr(strrchr($filename'.'), 1)=='php') ? true false;
        
});

        foreach (
$controller_files as $filename)
        
{
            
require_once('./application/controllers/'.$filename);

            
$classname ucfirst(substr($filename0strrpos($filename'.')));
            
$controller = new $classname();
            
$methods get_class_methods($controller);

            foreach (
$methods as $method)
            
{
                array_push
($methods,$method);
            
}

            $controller_info 
= array(
                
'filename' => $filename,
                
'class_name' => $classname,
                
'methods'  => $methods
            
);
            
array_push($controllers,$controller_info);
        
}

        
echo('<pre>');
        
print_r($controllers);
        echo(
'</pre>');
    
}
}
/* End of file controllers.php */
/* Location: ./application/controllers/controllers.php */ 

If you wanted, you could classify the methods as public, private or static by following the example in this comment: http://www.php.net/manual/en/function.method-exists.php#94112

 
Posted: 15 January 2012 10:21 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6267 posts

You people should really take a look at the CI Router Class!

// fetch the Controller!
$controller $this->CI->router->fetch_class();

// fetch the method!
$method $this->CI->router->fetch_method();

// fetch the directory!
$directory $this->CI->router->fetch_directory();

// fetch all controller methods
 // --------------------------------------------------------------------

 /**
  * get_controller_methods()
  *
  * Description:
  *
  * @access public
         * @param       string
  * @return array
  */
 
public function get_controller_methods($controller_name)
 
{
  $ctrl_methods 
= array();

  
$ctrl_methods get_class_methods($controller_name);

  return 
$ctrl_methods;
 

 

 Signature 

Ceritfied State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View

 
Posted: 12 July 2012 10:46 AM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Joined: 2010-02-09
11 posts

Hi,

bclinton’s class really did the trick for me. However, I would like to suggest few update for it.

$classname ucfirst(substr($filename0strrpos($filename'.')));
$controller = new $classname();
$methods get_class_methods($controller);

//$controller = new $classname();
$methods get_class_methods($classname); 

Reasons:

1. There is no need to instantiate the class. We can simply pass class name and it will give us the methods.
2. If controllers are looking for valid sessions, it will keep redirecting you to the login page.
3. In case you are using Matchbox, HMVC, it will not load supporting libraries.

I thought it worth giving my input, but thanks for the kick off.

-Rahi