@@ -5,3 +5,70 @@ Persistent user-specific settings for CodeIgniter 4
55[ ![ ] ( https://github.com/tattersoftware/codeigniter4-preferences/workflows/PHPStan/badge.svg )] ( https://github.com/tattersoftware/codeigniter4-preferences/actions/workflows/analyze.yml )
66[ ![ ] ( https://github.com/tattersoftware/codeigniter4-preferences/workflows/Deptrac/badge.svg )] ( https://github.com/tattersoftware/codeigniter4-preferences/actions/workflows/inspect.yml )
77[ ![ Coverage Status] ( https://coveralls.io/repos/github/tattersoftware/codeigniter4-preferences/badge.svg?branch=develop )] ( https://coveralls.io/github/tattersoftware/codeigniter4-preferences?branch=develop )
8+
9+ ## Quick Start
10+
11+ 1 . Install with Composer: ` > composer require --dev tatter/preferences `
12+ 2 . Load the helper: ` helper('preferences'); `
13+ 3 . Use the function to get and set: ` $theme = preference('theme'); preference('theme', 'dark'); `
14+
15+ ## Description
16+
17+ ` Preferences ` is a wrapper for [ CodeIgniter Settings] ( https://github.com/codeigniter4/settings )
18+ to provide authenticated user context to each setting. This allows you to get and set preferences
19+ on a per-user basis with a single command.
20+
21+ ## Installation
22+
23+ Install easily via Composer to take advantage of CodeIgniter 4's autoloading capabilities
24+ and always be up-to-date:
25+ * ` > composer require tatter/preferences `
26+
27+ Or, install manually by downloading the source files and adding the directory to
28+ ` app/Config/Autoload.php ` .
29+
30+ Once the files are downloaded and included in the autoload, run any library migrations
31+ to ensure the database is set up correctly:
32+ * ` > php spark migrate -all `
33+
34+ ` Preferences ` requires the Composer provision for ` codeigniter4/authentication-implementation ` as describe in the
35+ [ CodeIgniter authentication guidelines] ( https://codeigniter4.github.io/CodeIgniter4/extending/authentication.html ) ,
36+ so be sure to install a [ supported package] ( https://packagist.org/providers/codeigniter4/authentication-implementation )
37+ as well.
38+
39+ ## Usage
40+
41+ ` Preferences ` requires [ CodeIgniter Settings] ( https://github.com/codeigniter4/settings ) so
42+ you may use all the same classes and functions described in its documentation as well. To
43+ access the user-specific context settings call the ` preference() ` function anywhere you would
44+ normally use ` setting() ` :
45+
46+ ``` php
47+ class Home extends Controller
48+ {
49+ public function index()
50+ {
51+ return view('welcome', [
52+ 'theme' => preference('theme'),
53+ ];
54+ }
55+
56+ public function update_theme()
57+ {
58+ if ($theme = $this->request->getPost('theme')) {
59+ prefernece('theme', $theme);
60+ }
61+
62+ return redirect()->back();
63+ }
64+ }
65+ ```
66+
67+ > Note: Be sure to load the helper file (` helper('preferences') ` ) before using the helper function.
68+
69+ ## Troubleshooting
70+
71+ ` Preferences ` is a very "thin" library conjoining ` Settings ` and your authentication library
72+ of choice. Most likely any issues are related to one of the underlying libraries and should
73+ be directed there, but if you believe there is a problem or a feature request appropriate to
74+ this repository then feel free to open an Issue or Pull Request.
0 commit comments