ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Codeigniter Netbeans autocompletion generator

March 26, 2011 3:20pm

Subscribe [2]
  • #1 / Mar 26, 2011 3:20pm

    Nicolas Santos

    10 posts

    Hi all,

    I use netbeans and CI for a while now. Autocompletion is really missing. i found some tips like
    this one but i’m quite lazy… so i wrote a @property generator :D that is available within all the project and with i can access all my libs / models.

    * Tested in CI 2.0
    * copy paste the code in a protected controller
    * Just put the downloaded file in your application folder
    * if you want the loaded class like loader / db… add a parameter in your URL.

    If someone find the phpdoc syntax to allow the completion in a library - where you call CI from the get_instance(). ($this->ci)

    function generate_autocompletion($with_declared_classes = FALSE) {
            $this->load->helper("file");
            $this->load->helper("download");
    
            $classes = array();
            if ((bool) $with_declared_classes === TRUE) {
                $declared = get_declared_classes();
    
                foreach ($declared as $class) {
                    if (strpos($class, "CI_") === 0) {
                        $classes[str_replace("CI_", FALSE, $class)] = $class;
                    }
                }
            }
    
            $libs = get_filenames(APPPATH . "libraries/", FALSE, TRUE);
            foreach ($libs as $file) {
                $file = str_replace(".php", FALSE, $file);
                $classes[str_replace("MY_", FALSE, $file)] = $file;
            }
            $files = get_filenames(APPPATH . "models/", FALSE, TRUE);
            foreach ($files as $file) {
                $file = str_replace(".php", FALSE, $file);
                $classes[str_replace("MY_", FALSE, $file)] = $file;
            }
            $class_property = " /**\n";
            $class_property.= "  *\n";
            foreach ($classes as $key => $value) {
                $class_property.= "  * @property {$key} \${$value}\n";
            }
            $class_property.= "  */\n";
    
            $declaration = $class_property . "Class CI_Model{}\n";
            $declaration .= $class_property . "Class CI_Controller{}\n";
    
            foreach ($libs as $file) {
                $lib = str_replace(".php", FALSE, str_replace("MY_", FALSE,  $file));
                $declaration .= $class_property . "Class {$lib}{}\n";
            }
            force_download("autocompletion.php", "<?php \n{$declaration}\n?>");
        }

    ps : tried to post in the wiki but not allowed. Someone allowed can post it if he wants.

  • #2 / Sep 09, 2011 6:56am

    Niloco

    1 posts

    Hi,

    Looks good. Im lazy too.
    What Netbeans version are you using?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases