I’m working on my first add-on for EE and can’t seem to figure out how to handle settings. I’ve got an extension and an accessory setup just fine. Settings in the extension get saved to the database and everything loads from the accessory as expected. But once I start trying to do stuff with the settings in the accessory I get lost.
What I want to do is add some conditionals to the accessory based on those extension settings.
I’ve tried just calling this: $this->settings[‘variable’];
But if I use that to set a variable or do a conditional, I get errors like: “Uninitialized string offset” and “Cannot modify header information”.
What am I missing?
You’ll need to get the settings from the DB manually. Example (there are multiple ways):
$settings_query = $this->EE->db->select('settings')->where('class', 'Class_name_ext')->limit(1)->get('extensions');
$settings = ($settings_query->num_rows() > 0) ? $settings_query->result_array() : array() ;Thanks so much for the tip Erik. I think it’s working as I can get settings to echo in the array, but it just spits out “Array”. I looked up result_array in the CodeIgniter docs and got even more confused.
I tried adding this after your code and that didn’t seem to work.
$highlight = $settings['highlight_color'];Apologies for the novice questions, I’m sure this info is out there somewhere I just can’t seem to make it click.
Hi,
Accessories and extensions are different addon types. They don’t share any settings. In your accessory you will need to grab the extension settings yourself.
I am going to assume a couple of stuff: 1. Your extension class name: My_foo_ext 2. Same settings for all your extension hooks. (yes you can have different settings for each one, but thats another topic)
Directly from the DB
$settings = array();
$query = $this->EE->db->select('settings')->from('exp_extensions')->where('class', 'My_foo_ext')->limit(1)->get();
if ($query->num_rows() > 0)
{
$settings = @unserialize($query->row('settings'));
if ($settings ==== FALSE) $settings = array();
}
// $settings now holds your extension settingsI have not tested it for PHP errors. But should work fine.
Hope it helped!
You’ll need to get the settings from the DB manually. Example (there are multiple ways):$settings_query = $this->EE->db->select('settings')->where('class', 'Class_name_ext')->limit(1)->get('extensions'); $settings = ($settings_query->num_rows() > 0) ? $settings_query->result_array() : array() ;
You beat me to it.. Don’t forget to unserialize() it!
You beat me to it.. Don’t forget to unserialize() it!
Good call.
Seamus, I’d use this instead:
$settings_query = $this->EE->db->select('settings')->where('class', 'Class_name_ext')->limit(1)->get('extensions');
$settings = ($settings_query->num_rows() > 0) ? @unserialize($settings_query->row()->settings) : array() ;Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.