Welcome Guest, Not a member yet? Register   Sign In
Modular Extensions - HMVC version 5.2

[eluser]wiredesignz[/eluser]
@Ethan, Sorry for the slow reply.

As a matter of interest to ME users, Can you show us your extension to load files from other modules please?

[eluser]Ethan Dunham[/eluser]
I am a bit embarrassed because I am a merely a designer posing as a php developer. %-P Anyway here's what I did:

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Modular Extensions loader class extension
*
* install this file as application/libraries/MX_Loader.php
*
**/
class MX_Loader extends Loader
{
        

    /** Load a module config file **/
    public function module_config($file = '', $use_sections = FALSE, $module = NULL)
    {

        $ci = modules::$registry[$this->_class];
        
        $module = ($module == NULL ? $this->_module : $module);
        
        $file = (empty($file)) ? 'config' : $file;
        
        // prepend the name of the module to the actual filename
        $loadedfilename = $module ."_". $file;

        if (in_array($loadedfilename, $ci->config->is_loaded, TRUE))

            return $ci->config->item($loadedfilename);

        list($path, $file) = modules::find($file, $module, 'config/');
        
        if ($path === FALSE)
        {
            self::$loader->module_config($file, TRUE, $module);
                        
            return $ci->config->item($loadedfilename);
        }
        
        if ($config = modules::load_file($file, $path, 'config'))
        {
            /* reference to the config object */
            $current_config =& $ci->config->config;

            if ($use_sections === TRUE)
            {
                if (isset($current_config[$loadedfilename]))
                {
                    $current_config[$loadedfilename] = array_merge($current_config[$loadedfilename], $config);
                }
                else
                {
                    $current_config[$loadedfilename] = $config;
                }
            }
            else
            {
                $current_config = array_merge($current_config, $config);
            }

            $ci->config->is_loaded[] = $loadedfilename;

            unset($config);
            return $ci->config->item($loadedfilename);
        }
    }
}

Honestly not sure if this is 100% correct, but the changes I made work so far without issue. The key for me was to make sure the array that saved the names of the config files was unique. To do that I prepended the name of the module to the name of the config file and saved that as the name. Make sense?

Anyway, compare this to the ME config loader function to see the changes I made. Thanks, and suggestions welcome!

Ethan

[eluser]wiredesignz[/eluser]
Thanks for this Ethan, I'm sure it will be helpful to others looking to extend ME. Wink

[eluser]Ethan Dunham[/eluser]
My pleasure. In fact I wish I could think of more ways to give back, as CI and the community have been incredible. My thanks to you for what should be a core library. E

[eluser]BDT[/eluser]
Is there any way for use __construct in MX_Loader?

[eluser]BDT[/eluser]
hmm, i create pre_controller hook and in hook function call MX_Loader::testfunction() and work.
It is bad solution for call my base classes loader before controller loaded?
(i want to load 1-2 class from my shared classes before any controller constructor called)

[eluser]BDT[/eluser]
I have one hook where i call module for get module library function data.
In the module contructor i have the $this->load->library('testlib') and $this->load->model('testmodel'). This library and model is inside the modul library/ and models/ directory.

So when i call module::run from hook the actual controller is defaultcontroller (site home) and the test module contructor library loading ($this->load->library) try to load defaultcontroller library but i need to load testlib from test module not defaultcontroller testlib.

I hope you understand what i want to write...
What is the best solution for this problem? Please help me a little.

[eluser]BDT[/eluser]
Temporarily the only solution what I found it: I modify it the HMVC Controller.php
Code:
public function model($model, $object_name = NULL, $connect = FALSE)
{
...
}
to
Code:
public function model($model, $object_name = NULL, $connect = FALSE, module = NULL)
{
  if(!is_null($module) and $module!==$this->_module){
     $this->_module = $module;
  }

...
}

,and all my module library use $this->load->model with module parameter when i want to call module library function from hook or another module.

May be not the best solution but works and I had to solve this quickly. I would have loved of course in that manner, that not modify the controller.php -t

Now i test this in my dev site...

[eluser]BDT[/eluser]
I talk only with myself :roll:

[eluser]wiredesignz[/eluser]
[quote author="BDT" date="1226676816"]Is there any way for use __construct in MX_Loader?[/quote]

@BDT,

constructor for MX_Loader extension is not needed, but you can of course overload any object class constructor in PHP as you wish.

Your other posts are about your personal coding syle and because I personally don't use hooks in that fashion, it's difficult to offer any comments either way. Maybe somenone else does and can.

Good luck. Wink




Theme © iAndrew 2016 - Forum software by © MyBB