Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
DbConfig - Store your app specific config setting in a DB rather than loads of config files
  • Hi all, I was getting tired of having to create and manage loads of config files for things like Modules or simple general app specific settings so I quickly created DbConfig. This is a simple class that you place in the app/classes folder.
    //Usage example:
    echo dbConfig::get('telephone');
    dbConfig::set('telephone', 'xxxx xxxxxx');
    
    
    I hope you will find this useful. Phil.
  • FYI I added the autoload and autosave abilities to the class. You can use them by setting autoload and autosave to true in config/dbconfig.php. At runtime you can set it by setting the class variables $autoload and $autosave respectively to true... No extra arguments have been added to the class methods.
  • Thanks nerdsrescueme. I quite like the idea of the settings in config good call there. Turned out quite well I think with lots of flexibility. Not a criticism in anyway Just a couple of small things I would have done slightly differently... I noticed is that you have a default setting of true for $installed in _init I would probably have set that to false? I would have done a try catch in _install_db with $if_not_exists set to true maybe? Changes are still in the develop branch just in case you missed that. Anyway I am very pleased that you could see the potential with this and that you picked this up. You have done a great job with it thanks it is much appreciated. I also see that you picked up the blog as well. That is also looking good to the point where I may throw mine away and use yours he he. Thanks again nerdsrescueme. Phil.
  • All are good suggestions, I left it in the develop branch until I had a chance to use the class and find any logic bugs... I'm actually going to implement the changes you suggest and push them tonight. Thanks for all your help, and your idea :)
  • And the blog module is coming along quite nicely, it's slow going so far as everything has to be modular, and I'm not using the ORM for all those extra bells and whistles... It should be stable soon enough as a basic module, then hopefully I can get some pull requests for some more advanced functionality.
  • Had a minute, pushed those changes to the develop branch, if all is well I will master merge tonight.
  • lol :) You appear to have lots of free minutes available wish I had :( But your is spent doing great coding :) Do you get on the IRC at all? freenode #fuelphp The guys on there are great. They helped me get my head around GIT a little last night so all I can say is watch out world I am now GIT enabled (well sort of) :)
  • Only have free minutes lately. Planned a small slump in my workload so I could work on some personal stuff refresh and work with some new tools. Glad you like the packages I'm working on :) do you know of any good irc clients for Mac? I haven't used irc in years
  • I use x-chat as I am on windows but I think they do one for mac or you could use babble or Colloquy.
  • I really liked this idea, so I rolled with it... Here's a package for DbConfig... It duplicates the functionality of the current config class... http://github.com/ninjarite/fuel-dbconfig :)
  • It's really nice :) thanks.
  • Hi, WOW! It took me 10 minutes to write the class yesterday and today it's a Fuel package. Didn't expect that. When I wrote it I thought this is going to save me soooooo much time hence the initial post as I thought others could also benefit. Thanks nerdsrescueme good job. Phil.
  • Something strange going on... Using the latest Fuel core downloaded today. The \Config::load is not working as expected. It should be loading the dbconfig config file and merging it with the root config but it doesn't for some reason so the values from the dbconfig config are not being loaded in the following \Config::gets hence the table name can't be found if you remove the default off the end of the \Config::get and $installed always equals false. The result is that the config file and the db are being created every time. I altered the \Config::load('dbconfig'); to \Config::load('dbconfig' , true); so it is loaded into it's own group and it works as expected. I then checked the Auth package and this also loads it's config \Config::load('auth', true); so may have found an issue unless thats how it's designed to work and you have to load this way in packages will investigate later if I have time / remember. Will carry on testing now...
  • I was under the assumption it uses yhe filename as the group if none is provided. Please let me know what you find. And thanks for your hard work.
  • Thats correct if it's set to true If empty or null then should add to the root config. Easy to test just comment out the defaults at the ends of the \Config::gets To fix add true as the last parameter \Config::load('dbconfig', true);
  • Fixed sir, thanks so much! Pushed up the fix in master branch.
  • Just a thought... Could automate \DbConfig::load and \DbConfig::save If you do a \DbConfig::get('contact.company'); without \DbConfig::load('contact'); first nothing is returned because nothing is loaded. What about adding a third parameter to cause auto loading and auto saving example: \DbConfig::get('contact.company', null, true);
    automatically calls \DbConfig::load('contact');
    and the same for
    \DbConfig::set('contact.company', 'My Company', true);
    automatically calls \DbConfig::load('contact'); then process the \DbConfig::set() then
    \DbConfig::save('contact', \DbConfig::get('contact')); Obviously need to check to see if they are loaded first. Less code to write :-)
  • Sorry that sounded like I was asking you to code it for me. It was meant as a discussion point I can do the coding for you if you think its a good idea.
  • I don't see why I couldn't do that, it would affect the current implementation...
  • Sorry not sure what you mean by "affect the current implementation... "
  • I just meant that I enjoy that it emulates the fuel configuration class. Adding that idea won't change it, just enhance it.
  • is the package usable ?
    i tried and failed no table is created no value saved
    i autoload the package
    in config i have return array ('db' => array ('table' => 'config','installed' => false,'autoload' => true,'autosave' => true,),);
    in controller i call DbConfig::set('key', 'value');
  • Let me check to see if the 1.0 release changed anything I don't think it should have. I am using the package in several places so I'm no sure of the hold up here. The init method should auto install the database table on the first use of the class.
  • I'm not exactly certain what happened, but it seems the master branch was changed to load the configuration into the default config array... Fixed. Please update the package and let me know if this helped you.
  • redownloaded
    now i get a Fuel\Core\Fuel_Exception [ Error ]: DbConfig: value passed to DbConfig::save() must be an array
    when i call like this DbConfig::set('key', 'value'); i have autload false autosave true

Howdy, Stranger!

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

In this Discussion