We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Question about Add-on Development > Services > Config Service

Development and Programming

Richard Whitmer's avatar
Richard Whitmer
96 posts
10 years ago
Richard Whitmer's avatar Richard Whitmer

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?

       
Richard Whitmer's avatar
Richard Whitmer
96 posts
10 years ago
Richard Whitmer's avatar Richard Whitmer

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.

  • You can name your config files inside the directory “config” or some other name.
  • That file should return an array named “$config”
  • In your add-on files access the items using the Config service “get” method.

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

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.