@@ -39,15 +39,23 @@ In order to store the settings in the database, you can run the provided migrati
3939
4040This will also migrate all other packages. If you don't want to do that you can copy the file
4141from ` vendor/codeigniter4/settings/src/Database/Migrations/2021-07-04-041948_CreateSettingsTable.php `
42- into ` app/Database/Migrations ` , and migrate without the ` --all ` flag.
42+ into ` app/Database/Migrations ` , and migrate without the ` --all ` flag.
43+
44+ ## dot Notation
45+
46+ This library uses what we call "dot notation" to specify the class name and the property name to use.
47+ These are joined by a dot, hence the name.
48+
49+ If you have a class named ` App ` , and the property you are wanting to use is ` siteName ` , then the key
50+ would be ` App.siteName ` .
4351
4452## Usage
4553
4654To retrieve a config value use the ` settings ` service.
4755
4856``` php
4957// The same as config('App')->siteName;
50- $siteName = service('settings')->get('App', ' siteName');
58+ $siteName = service('settings')->get('App. siteName');
5159```
5260
5361In this case we used the short class name, ` App ` , which the ` config() ` method automatically locates within the
@@ -62,7 +70,14 @@ will be converted back into a boolean when retrieved. Arrays and objects are ser
6270when retrieved.
6371
6472``` php
65- service('setting')->set('App', 'siteName', 'My Great Site');
73+ service('setting')->set('App.siteName', 'My Great Site');
74+ ```
75+
76+ You can delete a value from the persistent storage with the ` forget() ` method. Since it is removed from the storage,
77+ it effectively resets itself back to the default value in config file, if any.
78+
79+ ``` php
80+ service('setting')->forget('App.siteName')
6681```
6782
6883### Using the Helper
@@ -73,12 +88,33 @@ or telling your BaseController to always load it.
7388``` php
7489helper('setting');
7590
76- // Using 'dot' syntax to separate class and field name
7791$name = setting('App.siteName');
7892// Store a value
79- setting('App.sitename ', 'My Great Site');
93+ setting('App.siteName ', 'My Great Site');
8094
8195// Using the service through the helper
82- $name = setting()->get('App', 'siteName');
83- $setting()->set('App', 'siteName', 'My Great Site');
96+ $name = setting()->get('App.siteName');
97+ setting()->set('App.siteName', 'My Great Site');
98+
99+ // Forgetting a value
100+ setting()->forget('App.siteName');
84101```
102+
103+ ## Known Limitations
104+
105+ The following are known limitations of the library:
106+
107+ 1 . Using the ` setting() ` helper method does not support setting a ` null ` value on a property. For most cases, you are
108+ better off forgetting the value or setting it to an empty string. If you need to, you can set it by grabbing
109+ the service and using the ` set() ` method:
110+
111+ ``` php
112+ service('settings')->set('App.siteName', null);
113+ setting()->set('App.siteName', null);
114+ ```
115+
116+ 2 . You can currently only store a single setting at a time. While the ` DatabaseHandler ` uses a local cache to
117+ keep performance as high as possible for reads, writes must be done one at a time.
118+ 3 . You can only access the first level within a property directly. In most config classes this is a non-issue,
119+ since the properties are simple values. Some config files, like the ` database ` file, contain properties that
120+ are arrays.
0 commit comments