You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-5Lines changed: 33 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,21 +42,20 @@ as well.
42
42
you may use all the same classes and functions described in its documentation as well. To
43
43
access the user-specific context settings call the `preference()` function anywhere you would
44
44
normally use `setting()`:
45
-
46
45
```php
47
46
class Home extends Controller
48
47
{
49
48
public function index()
50
49
{
51
50
return view('welcome', [
52
-
'theme' => preference('theme'),
51
+
'icon' => preference('Users.avatar'),
53
52
];
54
53
}
55
54
56
-
public function update_theme()
55
+
public function update_avatar()
57
56
{
58
-
if ($theme = $this->request->getPost('theme')) {
59
-
prefernece('theme', $theme);
57
+
if ($icon = $this->request->getPost('icon')) {
58
+
prefernece('Users.avatar', $icon);
60
59
}
61
60
62
61
return redirect()->back();
@@ -70,6 +69,35 @@ class Home extends Controller
70
69
If no user is authenticated then it will fall back on the `Session` class with semi-persistent
71
70
settings for as long as the session lasts.
72
71
72
+
### Placeholder Config
73
+
74
+
In most cases each setting should have a corresponding Config file. Sometimes these settings
75
+
will not fit under an existing logical grouping, so this library provides a "placeholder"
76
+
Config (`Tatter\Preferences\Config\Preferences`). You may add your own version in **app/* to
77
+
supply default values:
78
+
```php
79
+
<?php
80
+
81
+
namespace Config;
82
+
83
+
class Preferences extends \Tatter\Preferences\Config\Preferences
84
+
{
85
+
/**
86
+
* Slug for the current user theme.
87
+
*/
88
+
public string $theme = 'midnight';
89
+
}
90
+
```
91
+
92
+
Any function calls with the class unspecified will reference the `Preferences` class:
93
+
```php
94
+
// Identical calls:
95
+
$theme = preference('Preferences.theme');
96
+
$theme = preference('theme');
97
+
```
98
+
99
+
> Hint: Don't forget that libraries and modules can provide Config properties via [Registrars](https://codeigniter.com/user_guide/general/configuration.html#registrars)
100
+
73
101
## Troubleshooting
74
102
75
103
`Preferences` is a very "thin" library conjoining `Settings` and your authentication library
0 commit comments