Hey All, I’m slowly but surely working through the Services documentation in the EE3 Add-On Development section. This morning it’s the Config Service.
There are a couple things that probably should be obvious to me but aren’t:
Do I create the ./config/ directory in an my_addon’s directory? I haven’t seen a config directory any the directory structure of any of the add-ons I’ve looked at.
If so, what is the config filename? What is the format of that file? What does it look like? Is it a returned array like the one in /system/user/config/config.php?
Back to this… I’m posting what I was able to figure out using the simple example in the docs. It’s not much – just the Config Service Method. Anyhow, here goes. Hopefully it will some help other lost soul:
If your Add-On has config items specific to it, you can save those in files stored a config directory inside the add-on’s directory.
For example, if I’m creating an add-on named noisemakers. Inside the noisemakers directory, I’d create a config directory with my config files:
noisemakers
├── addon.setup.php
├── config
│ ├── config.php
│ ├── drums.php
The drums.php file would look something like this:
<?php
$config['kit'] = array('Bass','Snare','Hi-hat','Cowbell');
$config['fave'] = 'Cowbell';
return $config;
Then to get an add-on config item, such as favorite drum:
$fave = ee('Config')->get('gdtfiles:drums.fave');
It would still be great to see some simple examples of the other methods on that docs page. https://docs.expressionengine.com/latest/development/services/config.html
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.