Search code examples
phpfuelphpdata-mapping

FuelPHP - How to use Config::get($item) with a MySQL table?


I've created the table config with the default structure (from FuelPHP doc)

CREATE TABLE IF NOT EXISTS `config` (
  `identifier` char(100) NOT NULL,
  `config` longtext NOT NULL,
  `hash` char(13) NOT NULL,
  PRIMARY KEY (`identifier`)
)

but now, how can I access to that in my php code?

Config::get('DB.my_unique_indentifier') doesn't seem to work...


Solution

  • Ok, so the config.config field (MySQL) needs to be a serialized array when using the .db extension!


    to load from the database:

    Config::load('visio.db'); // where visio is the config key.
    

    to save a new config:

    Config::save('visio.db', array('my_param' => 'my_value'));
    

    Here's my way to play with it:

    $config = Config::load('visio.db');
    $jetons =& $config['jetons'];
    
    $jetons += 10;
    Debug::dump($jetons);
    $config = Config::save('visio.db', $config);
    

    Using Config::load('visio.my_param.db') doesn't work yet. This will may be implemented in FuelPHP 1.8 version.