CodeIgniter Forums
Preferences Library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Addins (https://forum.codeigniter.com/forum-34.html)
+--- Thread: Preferences Library (/thread-80597.html)



Preferences Library - MGatner - 11-19-2021

Hi all- With the advent of the official "CodeIgniter Settings" library (https://github.com/codeigniter4/settings) I've decided to deprecate my popular Settings library (https://github.com/tattersoftware/codeigniter4-settings) due to the significant overlap in name, features, and functionality. The biggest feature gap this leaves, however, is providing user-specific settings handling (e.g. allowing authenticated users to change their profile picture or set a theme). To fill this gap, I give you:
Tatter\Preferences
Persistent user-specific settings for CodeIgniter 4
https://github.com/tattersoftware/codeigniter4-preferences
https://packagist.org/packages/tatter/preferences
"Preferences" builds on "CodeIgniter Settings" and your authentication-library-of-choice to provide contextual settings for the authenticated user. Similar to Settings, there is a convenient helper function to turn this into a very easy set/get call. Here's a simplistic example of using dynamic themes for your users:
PHP Code:
class Home extends Controller
{
    public function index()
    {
        return view('welcome', [
            'theme' => preference('theme'),
        ];
    }

    public function update_theme()
    {
        if ($theme $this->request->getPost('theme')) {
            prefernece('theme'$theme);
        }

        return redirect()->back();
    }

As always, drop a comment here or stop by the repo with feature requests or feedback of any kind! Thanks for reading.