Elías Leyton
Elías Leyton

Reputation: 31

Call Config::Load doesn't work in Fuelphp

I have a class in the path 'app/classes' called 'Helper.php'. And also I have a config file 'custom.php' in 'app/config'.

The problem is, when I call the config file, this return FALSE.

class Helper {    
  public static function actions_header ($ractive) {    
    return Config::load('custom');    
  }
}

The custom config file

return array(
  'sidebar_entities' => array (
    array(
      'name' => 'Dashboard',
      'icon' => 'icon-dashboard',
      'url'  => 'dashboard'
    ),
    array(
      'name' => 'Álbumes',
      'icon' => 'icon-music',
      'url'  => 'albums'
    )
  )
);

Upvotes: 0

Views: 735

Answers (4)

zechdc
zechdc

Reputation: 3404

I have run into this issue as well. I run the following code. (I am running Fuel 1.6)

Config::load('config_file_name') //returns config array
Config::load('config_file_name') //returns false

Then I run the following to load a sub array of the config file.

Config::get('config_file_name.attr') //returns nothing

Turns out I just didn't understand the fuel documentation. Thanks @huglester, your answer made it all make sense for some reason.

The documentation says:

// This merges the "custom" config file in with the root config.
Config::load('custom');

// This loads the "custom" config file in a group named "custom".
Config::load('custom', true);

So, when you run Config::load('config_file_name'), you can access the config sub arrays by using Config::get('attr'). This is because the 'config_file_name' is merged with the root config.

If you want to use Config::get('config_file_name.attr'), then you need to load the config file using Config::load('config_file_name', true)

Upvotes: 0

WanWizard
WanWizard

Reputation: 2574

Up until 2012-08-28, load() only returned the loaded data on the initial call. If you called load() and the file is already loaded, it returned false. Since then, it will not load the file again, but return what is already loaded.

So the question is: how old is the version of Fuel you are using? Given the date of the change, that would be < 1.3, which is very old...

Upvotes: 0

huglester
huglester

Reputation: 116

You probably need something like this:

// load the config

Config::load('custom', true); // true - so you load the config to group 'custom'

// return array of items

return Config::get('custom');

I have not tested this, but something like this should work.

Upvotes: 1

Cyprezz
Cyprezz

Reputation: 53

Tried to repeat the same code and everything works fine for me. FuelPHP 1.7.

Upvotes: 0

Related Questions