Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Module config files
  • Hi, I'm trying to build a modular system using a Global Manager that detects modules and loads Module Managers so that the system works like a 'plugin' system where I put the module in the folder and it 'auto-loads' as it is detected. So far is looking good, but I'm stucked in the modules config folder. As this modules sometimes need some special configuration obviously, I'm trying to have a config file inside the modules that I would load into the Module Manager. So far I haven't had any luck, it seems like when I call
    \Config::load('moduleconfig', true);
    
    it doesn't find the file that's inside the module config folder. I don't know if I have to add some path somewhere or is it meant to work out-of-the-box; so I would appreciate if someone would shed some light into this. I've been working with FUEL for a couple of weeks now and so far I'm loving it! So much more flexible than CI (which I used to develop before); but sadly I must say that it is lacking of documentation. I understand that this project is just 'starting' and the efforts are put into the code so we'll have to be patient but I would love to see some improvements in the documentation explaining just how some things work inside FUEL, because as of now sometimes we have to struggle to understand how it works. Great work!
  • Config::load('Module\\config.php'); // where "Module" == the module namespace
    
  • That was a fast response! Sadly I must say it does not work... I have a module which namespace is PuAs so this looks like this:
    - app
        |- modules
             |- puas
                  |- classes
                       |- manager.php
                  |- config
                       |- config.php
                   |- views
    

    All files (including the config.php file) inside the module are namespaced with 'PuAs'. The config.php file has this content:
    <?php
    
    namespace PuAs;
    
    return array(
     'test' => 'success'
    );
    
    /* End of file config.php */
    

    I tried loading only the config file from within an app controller (welcome.php for example) using:
    var_dump(\Config::load('PuAs\\config.php'));
    
    following the instructions you gave me; but all I get in return is an empty array. I then tried to load it from the manager.php file but had the same result. Am I missing something? I was looking inside the load() function from the \Config class and it seems like it only searches files inside the global config folder, but does not look into module config folders. By the way: I do add the module using
    \Fuel::add_module('puas');
    
    on both examples.
  • Forgot one thing: this only works in the current develop branch, it's not in RC2. This is how it should work: https://github.com/fuel/core/blob/develop/classes/fuel.php#L243
    (Fuel::find_file() is the method used by Config::load(), Lang::load() and the View class)
  • Fantastic! Now it works! Thanks a lot! Keep up the good work, you are doing great!
    array(1) &#123;
      ["test"]=>
      string(4) "success"
    }
    
  • I just find a bug in FUEL::find_file function on line 259:
    https://github.com/fuel/core/blob/develop/classes/fuel.php#L259 The class caches the found path so that it has it on it's records. But now we have modules, so the directory structure can 'repeat' itself.
    If I have two modules: mod1 and mod2 having this structure (I wont put all folders as they are not need to show the point):
    - mod1
        |- config
             |- config.php
    
    -mod2
        |- config
             |- config.php
    

    and I run:
    $mod1_config = \Config::load('mod1\\config', true);
    $mod2_config = \Config::load('mod2\\config', true);
    

    then both vars will have the same contents, because of caching not using the namespace. Let me clarify this (fuel.php L259):
    $path = $directory.DS.strtolower($file).$ext;
    var_dump($path);
    
    will output in both cases:
    string(17) "config\config.php"
    

    if then, on line 261 we check for the cached path:
    if (static::$path_cache !== null and array_key_exists($cache_id.$path, static::$path_cache))
    {
     return static::$path_cache[$cache_id.$path];
    }
    

    the array key we are checking ($cache_id.$path) would be in both cases something like this:
    string(49) "d41d8cd98f00b204e9800998ecf8427econfig\config.php"
    
    which is wrong because they are two different paths!!! I think the namespace should be somewhere involved in assigning a key for the cached path.
  • I've already opened an issue on github: https://github.com/fuel/core/issues/84 UPDATED:
    Just one comment to clarify few things: When using modules I just figured out that the namespace must follow this rules so that this works:
    - The namespace must match the module name (that is the module folder's name)
    - The first character of the namespace should be upper-case (to follow the standard throughout FUEL) although it works if it does not (please, don't do it and stick to the standards!)
    - All (and I mean ALL) following characters MUST be lowercase (if some character is upper-case this DOESN'T WORK)
  • I'm closing this thread as any further comments on this should go to your github issue.
This discussion has been closed.
All Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion