Welcome Guest, Not a member yet? Register   Sign In
Modular Extensions - Version 4.3
#61

[eluser]Avatar[/eluser]
when trying to load any library from system/libraries with default module, no parents to this module. try to have a library to load from /modules/module/libraries will work, application/libraries/ will work, but system, libraries does not unless you make the modification I've suggested. Maybe you can perfect it for me. I know my code is sloppy, but this is for sure what is happening.
#62

[eluser]wiredesignz[/eluser]
Version 4.0.7 will include this fix to modular_extensions.php
Code:
//line 154
if (is_file(BASEPATH.'libraries/'.ucfirst($library).EXT))
{
    load_class(ucfirst($library), FALSE);    //uppercase library filenames are required
}
#63

[eluser]Avatar[/eluser]
it does the same thing for helpers located in BASEPATH.'system' as well
#64

[eluser]jbowman[/eluser]
[quote author="yingyes" date="1204708454"]try to load the view like this:
Code:
return $this->load->view('layout/header');
[/quote]

that was it, and I understand why. Thanks guys.
#65

[eluser]wiredesignz[/eluser]
Version 4.0.8 will have fixes for CI Helpers and Plugins Thanks yingyes Wink
#66

[eluser]Avatar[/eluser]
I've made another modification to modular_extension.php to the helper function this time:

Code:
function helper($helper)
    {
        if (is_file(BASEPATH.'helpers/'.$helper.EXT))
        {
            echo '<br />BLAH:'.BASEPATH.'helpers/'.$helper.EXT.'<br />';
            load_class($helper, FALSE);
        }
        list($path, $helper) = modules::path_to($helper, $this->_path, 'helpers/','_helper');
        
        if (isset($this->_ci_helpers[$helper]))
        {
            return;
        }
        
        if(modules::_load_file($helper, $path))
        {
            $this->_ci_helpers[$helper] = TRUE;
        }                
    }
and also th the modules_helper.php file path_to function
Code:
function path_to($file, $path = '', $base = '',$prep='')
    {
        $file = str_replace(EXT, '', strtolower($file));
        
        if (($pos = strrpos($file, '/')) !== FALSE)
        {
            $path  = substr($file, 0, $pos + 1);
            $file  = substr($file, $pos + 1);
        }
        else $path .= '/';
        
        foreach (array(MODBASE.$path.$base, MODBASE.$base, MODBASE.$path, MODBASE, APPPATH.$base, APPPATH.$base.$path, BASEPATH.$base) as $path2)
        {        
        
            foreach (array($file, ucfirst($file)) as $name)
            {
                if (is_file($path2.$name.$prep.EXT))
                {
                    return array($path2, $name.$prep);
                }
            }
        }

        if (class_exists('CI_'.$name))
        {
            return array(FALSE, $name);
        }    
        
        show_error("Unable to find the requested file: ".strtolower($path.$base.$file.EXT));
    }
THIS SMOOSHES THE HELPER BUG THAT IS THE SAME BUG WITH THE LIBRARIES, where it doesn't send the correct file name or file path. Please correct my mistake to optimize the library with what I've provided. This is AWESOME, that's the second time I've said that. Smile
Thank you.
#67

[eluser]Avatar[/eluser]
I'm bored. So I've decided to post my version of the modules_helper.php and modular_extensions.php Hope this is helpful., please see below:
modules_helper.php
Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Modular Extensions - (HMVC)
*
* Adapted from the CodeIgniter Core Classes
* @copyright    Copyright (c) 2006, EllisLab, Inc.
* @license        http://ellislab.com/codeigniter/user-guide/license.html
*
* Description:
* This helper provides static functions to load and instantiate modules
* from the modular_extensions library which can operate as HMVC controllers.
*  
* Modules have access to the currently loaded core classes in the same
* manner as a normal controller.
*
* Install this file as application/helpers/modules_helper.php
*
* Load manually or autoload as needed.
*
* Version: 4.0.6 (c) Wiredesignz 2008-03-04
**/

define('MODBASE', APPPATH.'modules/');

class Modules
{
    function & load($modules, $base = 'controllers/')
    {        
        if(!is_array($modules))
        {
            $modules = array($modules => '');
        }
        
        foreach ($modules as $module => $config)
        {            
            list($path, $module) = modules::path_to($module, $module, $base);
            
            if (isset($this->$module))
            {
               return $this->$module;
             }
        
            modules::_load_file($module, $path);
            
            $_module = strtolower($module);    
            $this->$_module =& new $module($config);
            
            $this->$_module->_modules[$_module] = get_class($this);
            
            return $this->$_module;  
        }
    }

    function _load_file($file, $path)
    {
        if (!class_exists($file))
        {
            include_once $path.$file.EXT;
            log_message('debug', $path.$file.EXT.' file loaded');
        }
        return TRUE;
    }
    
    function _load_config($file, $path)
    {
        include $path.$file.EXT;
        
        if (!isset($config) OR !is_array($config))
        {        
            show_error($file.' does not contain a valid configuration array');
        }

        log_message('debug', $path.$file.EXT.' configuration file loaded');
        return $config;
    }
    
    function path_to($file, $path = '', $base = '',$prep='')
    {
        $file = str_replace(EXT, '', strtolower($file));
        
        if (($pos = strrpos($file, '/')) !== FALSE)
        {
            $path  = substr($file, 0, $pos + 1);
            $file  = substr($file, $pos + 1);
        }
        else $path .= '/';
        
        foreach (array(MODBASE.$path.$base, MODBASE.$base, MODBASE.$path, MODBASE, APPPATH.$base, APPPATH.$base.$path, BASEPATH.$base) as $path2)
        {        
        
            foreach (array($file, ucfirst($file)) as $name)
            {
                if (is_file($path2.$name.$prep.EXT))
                {
                    return array($path2, $name.$prep);
                }
            }
        }

        if (class_exists('CI_'.$name))
        {
            return array(FALSE, $name);
        }    
        
        show_error("Unable to find the requested file: ".strtolower($path.$base.$file.EXT));
    }
    
    function run($module, $data = '', $method = 'index')
    {
        $class =& modules::load($module);
        return (method_exists($class, $method)) ? $class->$method($data) : $class->_error($method);
    }
    
    function debug($_this)
    {
        if (is_object($_this))
        {
            echo '<pre>',get_class($_this),' Object: ',
            print_r(array_keys(get_object_vars($_this)), TRUE),'</pre>';
            echo '<br />';
        }
    }
    
    function debug_in($_this)
    {
        if (is_object($_this))
        {
            echo '<pre>',get_class($_this),' Object: ',
            print_r(get_object_vars($_this), TRUE),'</pre>';
            echo '<br />';
        }
        
        if (is_array($_this))
        {
            echo '<pre>',
            print_r($_this, TRUE),'</pre>';
            echo '<br />';
        }
    }
    function to_string($module, $mod_str = '')
    {      
        $_mods = explode('/',$module);
            
        $pos = strrpos($module, '/');
        $fm  = substr($module, $pos + 1);
      
        foreach($_mods as $mod => $m)
        {
            $mod_str .= ($fm != $m) ? $m.'/modules/' : $fm.'/'.$fm;
        }
            
        return $mod_str;
    }
}

include_once APPPATH.'libraries/modular_extensions.php';
#68

[eluser]Avatar[/eluser]
Code:
class Module
{        
    var $_modules;
    
    function Module()
    {
        static $mods = array();
        $this->_modules =& $mods;
        
        $ci =& get_instance();
        
        $this->load =& new Loader($this);
        $this->load->_assign_libraries($this, $ci);
        $this->load->_ci_assign_to_models();
        
        log_message('debug', ucfirst(get_class($this))." module initialised");
    }
    
    function index()
    {
        log_message('error', ucfirst(get_class($this))." module: No index() method defined");
    }
    
    function _error($method)
    {
        log_message('error', ucfirst(get_class($this))." module: No ".$method."() method defined");
    }
}

class Loader extends CI_Loader
{    
    function Loader(&$module)
    {
        parent::CI_Loader();
        
        $this->module  =& $this;    /* reserved for future use */
        $this->_module =& $module;
        $this->_path   = get_class($module);
    }

    function _assign_libraries(&$_object, &$_parent)
    {
        $_this = ucfirst(get_class($_object));
        
        $obj_vars = array_keys(get_object_vars($_parent));
        foreach ($obj_vars as $key)
        {
            if (!isset($_object->$key) AND $key != $_this)
            {
                $_object->$key =& $_parent->$key;
            }
        }
    }
    
    function _assign_to_models()
    {
        if (count($this->_ci_models) == 0)
        {
            return;
        }
    
        foreach ($this->_ci_models as $model)
        {            
            $this->_module->$model->_assign_libraries($this->_module->$model, $this->_module);
        }
    }
    
    function module()
    {
        /* reserved for future use */
    }
    
    function config($file = '', $use_sections = FALSE)
    {            
        list($path, $file) = modules::path_to($file, $this->_path, 'config/');
        
        $file = ($file == '') ? 'config' : $file;
        
        if (in_array($file, $this->_module->config->is_loaded, TRUE))
        {
            return;
        }

        if ($config = modules::_load_config($file, $path))
        {            
            if ($use_sections == TRUE)
            {
                if (isset($this->_module->config->config[$file]))
                {
                    $this->_module->config->config[$file] = array_merge($this->_module->config->config[$file], $config);
                }
                else
                    $this->_module->config->config[$file] = $config;
            }
            else
                $this->_module->config->config = array_merge($this->_module->config->config, $config);
            
            $this->_module->config->is_loaded[] = $file;
        }
    }
    
    function helper($helper)
    {
        if (is_file(BASEPATH.'helpers/'.$helper.EXT))
        {
            echo '<br />BLAH:'.BASEPATH.'helpers/'.$helper.EXT.'<br />';
            load_class($helper, FALSE);
        }
        list($path, $helper) = modules::path_to($helper, $this->_path, 'helpers/','_helper');
        
        if (isset($this->_ci_helpers[$helper]))
        {
            return;
        }
        
        if(modules::_load_file($helper, $path))
        {
            $this->_ci_helpers[$helper] = TRUE;
        }                
    }

    function helpers($helpers = array())
    {
        if (!is_array($helpers))
        {
            $helpers = array($helpers);
        }
            
        foreach ($helpers as $helper)
        {
            $this->helper($helper);
        }
    }
    
    function library($library, $params = NULL)
    {
        if ($library == 'database') return parent::database();
        
        if (is_file(BASEPATH.'libraries/'.$library.EXT))
        {
            load_class($library, FALSE);
        }

        list($path, $library) = modules::path_to($library, $this->_path, 'libraries/');
        
        if (isset($this->_module->$library))
        {
           return;
         }
        
        
        
        if(modules::_load_file($library, $path))
        {        
            $_library = strtolower($library);
            if ($path != FALSE) $library = 'CI_'.$library;        
            $this->_module->$_library =& new $library($params);
            $this->_assign_to_models();
        }
    }
    
    function model($model, $alias = FALSE, $connect = TRUE)
    {
        list($path, $model) = modules::path_to($model, $this->_path, 'models/');
        
        $_alias = ($alias == FALSE) ? strtolower($model) : strtolower($alias);
        
        if (isset($this->_module->$_alias))
        {
            return;
        }
        
        if(!class_exists('Model'))
        {
            load_class('Model', FALSE);
        }
        
        if(modules::_load_file($model, $path))
        {
            if ($connect) parent::database();
            
            $this->_module->$_alias =& new $model();
            
            $this->_assign_libraries($this->_module->$_alias, $this->_module);
        }
    }
    
    function plugin($plugin)
    {
        list($path, $plugin) = modules::path_to($plugin, $this->_path, 'plugins/','_pi');
        
        if (isset($this->_ci_plugins[$plugin]))
        {
            return;
        }
        
        if(modules::_load_file($plugin, $path))
        {
            $this->_ci_plugins[$plugin] = TRUE;
        }
    }

    function plugins($plugins = array())
    {
        if (!is_array($plugins))
        {
            $plugins = array($plugins);
        }
            
        foreach ($plugins as $plugin)
        {
            $this->plugin($plugin);
        }
    }

    function view($view, $data = array(), $return = TRUE)
    {
        list($path, $view) = modules::path_to($view, $this->_path, 'views/');
        
        $this->_ci_view_path = $path;
        return parent::view($view, $data, $return);
      }
}
#69

[eluser]wiredesignz[/eluser]
Version 4.0.8 is available on the wiki. Thanks all.

I'm sure yingyes will test it thoroughly. :lol:
#70

[eluser]Avatar[/eluser]
yes, but I think for a little while not to expect any more rewrite as I test within the app and not so much the lib. I've been waiting for a lib like this for a while now. It's very powerful what you can do with modules and smarty combined. It's the least I could do you know, after all it's got potential.




Theme © iAndrew 2016 - Forum software by © MyBB