Search
 
SCRIPT & CODE EXAMPLE
 

PHP

List all controllers in codeigniter HMVC structure

class ControllerList {
      // Codeigniter reference 
    private $CI;

     // Array that will hold the controller names and methods
    private $aControllers;

    // Construct
    function __construct() {
        // Get Codeigniter instance 
        $this->CI = get_instance();

        // Get all controllers 
        $this->setControllers();

    }

    /**
     * Return all controllers and their methods
     * return array
     */
    public function getControllers() {
        return $this->aControllers;
    }

    /**
     * Set the array holding the controller name and methods
     */
    public function setControllerMethods($p_sControllerName, $p_aControllerMethods) {
         $this->aControllers[$p_sControllerName] = $p_aControllerMethods;
    }

    /**
     * Search and set controller and methods.
     */
    private function setControllers() {

        foreach(glob(APPPATH . 'modules/*') as $modules_all) {

            if(is_dir($modules_all)) {

                $dirname = basename($modules_all);

            foreach(glob(APPPATH . 'modules/'.$dirname.'/controllers/*') as $subdircontroller) {

                    $subdircontrollername = basename($subdircontroller, EXT);


                    if(!class_exists($subdircontrollername)) {
                        $this->CI->load->file($subdircontroller);
                    }

                    $aMethods = get_class_methods($subdircontrollername);
                    $aUserMethods = array();
                    foreach($aMethods as $method) {
                        if($method != '__construct' && $method != 'get_instance' && $method != $subdircontrollername) {
                            $aUserMethods[] = $method;
                        }
                    }
                    $this->setControllerMethods($subdircontrollername, $aUserMethods);                                      
                 }
            }
            else if(pathinfo($controller, PATHINFO_EXTENSION) == "php"){

                $controllername = basename($controller, EXT);


                if(!class_exists($controllername)) {
                    $this->CI->load->file($controller);
                }


                $aMethods = get_class_methods($controllername);
                $aUserMethods = array();
                if(is_array($aMethods)){
                    foreach($aMethods as $method) {
                        if($method != '__construct' && $method != 'get_instance' && $method != $controllername) {
                            $aUserMethods[] = $method;
                        }
                    }
                }

                $this->setControllerMethods($controllername, $aUserMethods);                                
            }
        } 
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: the_fiel 
Php :: create or update laravel 5.8 stackoverflow 
Php :: php delete acc 
Php :: ass 
Php :: detect mobile device laravel 
Php :: add code return block phpstorm 
Php :: response in xml laravel 
Php :: live search in ajax 
Php :: Add class to menu anchors 
Php :: dql if or ifnull 
Php :: unlink() in php 
Php :: route laravel 
Php :: find largest element of an array in php 
Php :: laravel model bind with route in model 
Php :: Select specefied columns from all data in laravel 
Php :: stripslash 
Php :: Laravel9 Failed to listen on 127.0.0.1:8000 (reason: ?) 
Php :: laravel transaction 
Php :: authenticate user with phone laravel 
Php :: php mask credit card number 
Java :: jlabel text center 
Java :: jenkins decrypt password script console 
Java :: read text file java to string 
Java :: fullscreen activity android 
Java :: java hashmap entryset 
Java :: Could not initialize class org.apache.maven.plugin.war.util.WebappStructureSerializer 
Java :: java remove first character from string 
Java :: java set textview color 
Java :: how to force garbage collection in java 
Java :: Howow to use font object Java 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =