Blesta Addons Posted August 31, 2014 Report Share Posted August 31, 2014 today i'm working in settings class for my plugin , i though that is better to make setsetting support array instead of 1 key/value . why ? this will help us as developper to add array of setting for one plugin . for exemple Array ( [0] => stdClass Object ( [key] => amazons3_access_key [value] => [encrypted] => 1 [level] => system ) [1] => stdClass Object ( [key] => amazons3_bucket [value] => [encrypted] => 0 [level] => system ) ..... ..... ..... [XX] => stdClass Object ( [key] => announcement_plugin [value] => Array ( [0] => stdClass Object ( [key] => setting_1 [value] => true ) [1] => stdClass Object ( [key] => setting_2 [value] => 325 ) ) [encrypted] => 0 [level] => system ) as we can delete this group of setting in one shoot if uninstalling the plugin . Quote Link to comment Share on other sites More sharing options...
Blesta Addons Posted August 31, 2014 Author Report Share Posted August 31, 2014 EDIT , i got what i want by a simple tip , so i will share it . let say you need to add settings to your plugin "my_plugin" ; so : $value = array('setting_1' => 12 , 'setting_2'=> "desc" , 'setting_3'=> "here some text"); // build the array of setting $this->Settings->setSetting("my_plugin", serialize($value) , $encrypted = null ); // save the settings the magic code here is serialize that convert array to string when you need to use the setting just call the function $value = $this->Settings->getSetting("my_plugin"); $vars = unserialize($value->value)); now you have a array of setting inthe $vars . hope this can help others . Quote Link to comment Share on other sites More sharing options...
Cody Posted August 31, 2014 Report Share Posted August 31, 2014 You should probably be using Company::setSetting() instead, since plugins are installed per-company. Also, you can use setSettings() after you create the settings for quick update. But install/uninstall could just loop through all settings your plugin creates. $settings = array('setting1', 'setting2', 'setting3'); // uninstall all plugin settings: foreach ($settings as $setting) { $this->Company->unsetSetting($company_id, $setting); } Michael 1 Quote Link to comment Share on other sites More sharing options...
Blesta Addons Posted August 31, 2014 Author Report Share Posted August 31, 2014 You should probably be using Company::setSetting() instead, since plugins are installed per-company. Also, you can use setSettings() after you create the settings for quick update. But install/uninstall could just loop through all settings your plugin creates. $settings = array('setting1', 'setting2', 'setting3'); // uninstall all plugin settings: foreach ($settings as $setting) { $this->Company->unsetSetting($company_id, $setting); } i was inthe road to ASK the question about the company_id and setsettings, as there are no way to make settings per company . your comment was in the correct time, i will try and see . Quote Link to comment Share on other sites More sharing options...
Blesta Addons Posted August 31, 2014 Author Report Share Posted August 31, 2014 Well Done as my previos post , i have grouped all the setting in 1 array , so in don't need to loop when uninstalling , just i provide the key plugin to delete it's settings . Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.