Skip to content

HMVC for DMZ Modular Separation

Derek Jones edited this page Jul 5, 2012 · 9 revisions

With this modification on DMZ class you will be able to use Modular Separation with DMZ

Topic for discusion: http://codeigniter.com/forums/viewthread/154350/

Tested on: [Modular Separation] 1.12 (http://codeigniter.com/wiki/Modular_Separation) [DMZ] 1.7.1 (http://www.overzealous.com/dmz/pages/download.html)

What is is? HMVC for DMZ Modular Separation 1.0 I always used the DMZ with CodeIgniter for organizing and developing my application, then I discovered that the Modular Separation helps organize my application further. But although the Modular Separation ja is well compatible with the DMZ, DMZ but not load the 'DMZ_Models' in the folder of a module and then I had the idea of editing to make it

Criticisms and suggestions contact me

[i]Portugues: Eu sempre usei o codeigniter com o DMZ para organizar e desenvolvimento minhas aplicação, então eu descobri o Modular Separation que ajuda a organizar mais ainda a minha aplicação. Mas embora o Modular Separation ja seja bem compativel com o DMZ, mas o DMZ não load os 'DMZ_Models' estiverem na pasta de um modulo e então eu tive a idéia de editar para fazer it

Criticas e sugestões me contate [/i]

How to use: Copy the original datamapper.php file from libraries directory and paste on your libraries module diretory and then edit it like this:

Replace this:

    public static function autoload($class)
    {
        // Don't attempt to autoload CI_ or MY_ prefixed classes
        if (in_array(substr($class, 0, 3), array('CI_', 'EE_', 'MY_')))
        {
            return;
        }

        // Prepare class
        $class = strtolower($class);

        $CI =& get_instance();

        // Prepare path
        if (isset($CI->load->_ci_model_paths) && is_array($CI->load->_ci_model_paths))
        {
            // use CI loader's model path
            $paths = $CI->load->_ci_model_paths;
        }
        else
        {
            $paths = array(APPPATH);
        }

        foreach ($paths as $path)
        {
            // Prepare file
            $file = $path . 'models/' . $class . EXT;

            // Check if file exists, require_once if it does
            if (file_exists($file))
            {
                require_once($file);
                break;
            }
        }

        // if class not loaded, do a recursive search of model paths for the class
        if (! class_exists($class))
        {
            foreach($paths as $path)
            {
                $found = DataMapper::recursive_require_once($class, $path . 'models');
                if($found)
                {
                    break;
                }
            }
        }
    }
  1. For this:
    public static function autoload($class)
    {
        // Don't attempt to autoload CI_ or MY_ prefixed classes
        if (in_array(substr($class, 0, 3), array('CI_', 'EE_', 'MY_')))
        {
            return;
        }

        // Prepare class
        $class = strtolower($class);

        $CI =& get_instance();

        // Prepare path
        if (isset($CI->load->_ci_model_paths) && is_array($CI->load->_ci_model_paths))
        {
            // use CI loader's model path
            $paths = $CI->load->_ci_model_paths;
        }
        else
        {
            $paths = array(APPPATH);
        }

        foreach ($paths as $path)
        {
            // Prepare file
            $file = $path . 'models/' . $class . EXT;
            
            // Check if file exist on module loaded, require_once if it does, if not, seach on application (Module is more importante than application
            $CI =& get_instance();
            $module = $CI->router->fetch_module();
            if(!empty($module) ){
                $file_module = $path . 'modules/' . $module . '/models/' . $class . EXT;
                if (file_exists($file_module))
                {
                    require_once($file_module);
                    $find_on_module = TRUE;
                    break;
                    
                }
            }
            
            // Check if file exists, require_once if it does
            if (file_exists($file) && !isset($find_on_module))
            {
                require_once($file);
                break;
            }
        }

        // if class not loaded, do a recursive search of model paths for the class
        if (! class_exists($class))
        {
            foreach($paths as $path)
            {
                if(!empty($module) ){
                    $found = DataMapper::recursive_require_once($class, $path . 'modules/' . $module . '/models');
                    if($found)
                    {
                        break;
                    }
                }
                $found = DataMapper::recursive_require_once($class, $path . 'models');
                if($found)
                {
                    break;
                }
            }
        }
    }

text: Category:DMZ Extensions

Clone this wiki locally