Download the PHP package tatter/preferences without Composer
On this page you can find all versions of the php package tatter/preferences. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tatter/preferences
More information about tatter/preferences
Files in tatter/preferences
Package preferences
Short Description Persistent user-specific settings for CodeIgniter 4
License MIT
Homepage https://github.com/tattersoftware/codeigniter4-preferences
Informations about the package preferences
Tatter\Preferences
Persistent user-specific settings for CodeIgniter 4
Quick Start
- Install with Composer:
> composer require --dev tatter/preferences
- Load the helper:
helper('preferences');
- Use the function to get and set:
$theme = preference('theme'); preference('theme', 'dark');
Description
Preferences
is a wrapper for CodeIgniter Settings
to provide user context to each setting. This allows you to get and set preferences on a
per-user basis with a single command.
Installation
Install easily via Composer to take advantage of CodeIgniter 4's autoloading capabilities and always be up-to-date:
Or, install manually by downloading the source files and adding the directory to
app/Config/Autoload.php
.
Once the files are downloaded and included in the autoload, run any library migrations to ensure the database is set up correctly:
> php spark migrate -all
Preferences
suggests the Composer provision for codeigniter4/authentication-implementation
as describe in the
CodeIgniter authentication guidelines.
Without this each preference will be limited to the session duration so it is highly recommended
you install and configure a supported package.
Usage
Preferences
requires CodeIgniter Settings so
you may use all the same classes and functions described in its documentation as well. To
access the user-specific context settings call the preference()
function anywhere you would
normally use setting()
:
Note: Be sure to load the helper file (
helper('preferences')
) before using the helper function.
preference()
will retrieve and store contextual settings for the current authenticated user.
If no user is authenticated then it will fall back on the Session
class with semi-persistent
settings for as long as the session lasts.
Placeholder Config
In most cases each setting should have a corresponding Config file. Sometimes these settings
will not fit under an existing logical grouping, so this library provides a "placeholder"
Config (Tatter\Preferences\Config\Preferences
). You may add your own version in *app/ to
supply default values:
Any function calls with the class unspecified will reference the Preferences
class:
Hint: Don't forget that libraries and modules can provide Config properties via Registrars
Troubleshooting
Preferences
is a very "thin" library conjoining Settings
and your authentication library
of choice. Most likely any issues are related to one of the underlying libraries and should
be directed there, but if you believe there is a problem or a feature request appropriate to
this repository then feel free to open an Issue or Pull Request.