Waffle Recipes

How-To's and Tutorials for the ActiveWAFL Framework

How to Store and Retrieve Custom Application Settings

Posted Nov 20, 2014

All ActiveWAFL applications have environment specific configurations that are stored in a Syrup file named "Config/Settings.<environment>.syrp".
By default, this file is populated with the basic required settings for an application.

If you want to add custom settings, you may add them to any section in the Syrup file.
You can then access these settings in your application by using the GetSettingsSection and GetSettingValue methods.

Setup a Custom Option

Example segment of a Syrup file that specifies a custom option named 'Foo' with a value of 'Bar' in the settings file's Application section
  1. Application
  2.     GuestGroupId                =   99
  3.     Foo                         =   Bar
  4. Web
  5.     DomainName                  =    "d.myapp.com"
  6.     WebUrl                      =    "http://d.myapp.com/"
  7.     WebUrlSecure                =    "https://d.myapp.com/"
  8.     and so on....

Get the Value of a Custom Option

Example controller action that reads a custom option named 'Foo' in the settings file's Application section and passes it along to the presentation layer
  1. namespace MyApp\Controllers;
  3. class MyController
  4. extends \DblEj\Mvc\ControllerBase
  5. {
  6.     public function DefaultAction(\DblEj\Communication\Http\Request $request, \DblEj\Application\IMvcWebApplication $app)
  7.     {
  8.         //read the value of the Foo setting from the settings file
  9.         $foo = app->GetSettingsSection("Application")->GetOptionValue("Foo");
  11.         //add the value of the Foo setting to a Model that can be used during view rendering
  12.         $viewModel = new \DblEj\Data\ArrayModel(["FOO"=>$foo]);
  14.         //pass the Model, which contains the value for the Foo setting, to be used by the view rendering engine and return the rendered view
  15.         return $this->createResponseFromRequest($request, $app, $viewModel);
  16.     }
  17. }


Using the Settings.<environment> file provides a quick and easy way to store environment specific settings and the corresponding methods provide a simple and standard way of reading those settings.
You can add your custom settings to any section of the settings file, or you may create new custom sections to put them under.

Note: The application provides several methods for directly accessing a section in the settings file.
For example, $app->Get_Settings()->Get_Web() is the same as app->GetSettingsSection("Web")