Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Module config usage
  • Hi fellow Fuelers, Just trying to get to the bottom of this small dilemma. I have moved to a module layout for my application, however, one thing that is stumping me is pre-loading config files on modules to the main app itself. Example. fuel/app/modules/mod1/config/config.php contains:
    return array(
      'sidebar' => array(
        'mod1' => array(
          'method1' => 'Nice title',
          'method2' => 'Nice title 2',
        ),
      ),
    );
    

    In my application controller I am trying to load the module (either in config.php or using Fuel::add_module("mod1" )) However, I am getting back no results at all.
    Fuel::add_module('mod1');
    Debug::dump(Config::get('config'));
    
    Variable #1:
    NULL
    

    2 problems apparent from this.. 1. I am obviously not seeing the config file present
    1. Shouldn't I be seeing the base config.php array in this dump as a complete merge? I have also tried creating the config file as 'sidebar' with the exact same results (after changing the Config::get() to reflect this. I know I am missing something really simple and possibly stupid but I just can't seem to see it. Any help or a nudge in the correct direction would be invaluable at this point. PS. I have also used Debug::dump(Config::load('mod1::sidebar')); which does work but wanted this to work across all modules installed. Thanks Edit: Removed the smiley caused by using " ) next to each other..
  • You have to load the config file first.
    Config::load('config');
    

    I would recommend naming your config files the same as your modules.
  • @derek,
    Config::load('config');
    

    Tried that also, to no avail.
    I would recommend naming your config files the same as your modules.

    Unfortunately for what I am trying to achieve that wouldn't work, I needed an array that contained the merge of a config file contained within every module. I wouldn't know what the module names are before they were added to the directory.
  • The finder works with a "request context". This is determined by the Request. The fact that you tell FuelPHP that you have a module somewhere doesn't change the context. So if you're controller that wants to load this config file is in app (or in another module), that is the context, it is not magically going to look elsewhere. If you explicitly want to load from a module, use
    \Config::load('modulename::config');
    

Howdy, Stranger!

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

In this Discussion