{"id":15046415,"url":"https://github.com/tattersoftware/codeigniter4-preferences","last_synced_at":"2025-06-26T07:31:59.584Z","repository":{"id":40662896,"uuid":"427404716","full_name":"tattersoftware/codeigniter4-preferences","owner":"tattersoftware","description":"Persistent user-specific settings for CodeIgniter 4","archived":false,"fork":false,"pushed_at":"2024-05-23T09:53:08.000Z","size":54,"stargazers_count":6,"open_issues_count":1,"forks_count":2,"subscribers_count":5,"default_branch":"develop","last_synced_at":"2025-05-18T12:07:22.551Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tattersoftware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-12T15:19:11.000Z","updated_at":"2025-01-19T23:09:49.000Z","dependencies_parsed_at":"2024-06-21T16:45:27.485Z","dependency_job_id":"26a22c4a-9b9b-4aa3-9263-1689ea08a493","html_url":"https://github.com/tattersoftware/codeigniter4-preferences","commit_stats":{"total_commits":11,"total_committers":1,"mean_commits":11.0,"dds":0.0,"last_synced_commit":"0e2ac8d40adae805a92215bcfb2ff5cf225b34b8"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/tattersoftware/codeigniter4-preferences","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-preferences","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-preferences/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-preferences/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-preferences/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tattersoftware","download_url":"https://codeload.github.com/tattersoftware/codeigniter4-preferences/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-preferences/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261200146,"owners_count":23123920,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T20:53:05.054Z","updated_at":"2025-06-26T07:31:59.562Z","avatar_url":"https://github.com/tattersoftware.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tatter\\Preferences\nPersistent user-specific settings for CodeIgniter 4\n\n[![](https://github.com/tattersoftware/codeigniter4-preferences/workflows/PHPUnit/badge.svg)](https://github.com/tattersoftware/codeigniter4-preferences/actions/workflows/test.yml)\n[![](https://github.com/tattersoftware/codeigniter4-preferences/workflows/PHPStan/badge.svg)](https://github.com/tattersoftware/codeigniter4-preferences/actions/workflows/analyze.yml)\n[![](https://github.com/tattersoftware/codeigniter4-preferences/workflows/Deptrac/badge.svg)](https://github.com/tattersoftware/codeigniter4-preferences/actions/workflows/inspect.yml)\n[![Coverage Status](https://coveralls.io/repos/github/tattersoftware/codeigniter4-preferences/badge.svg?branch=develop)](https://coveralls.io/github/tattersoftware/codeigniter4-preferences?branch=develop)\n\n## Quick Start\n\n1. Install with Composer: `\u003e composer require --dev tatter/preferences`\n2. Load the helper: `helper('preferences');`\n3. Use the function to get and set: `$theme = preference('theme'); preference('theme', 'dark');`\n\n## Description\n\n`Preferences` is a wrapper for [CodeIgniter Settings](https://github.com/codeigniter4/settings)\nto provide user context to each setting. This allows you to get and set preferences on a\nper-user basis with a single command.\n\n## Installation\n\nInstall easily via Composer to take advantage of CodeIgniter 4's autoloading capabilities\nand always be up-to-date:\n```bash\ncomposer require tatter/preferences\n```\n\nOr, install manually by downloading the source files and adding the directory to\n`app/Config/Autoload.php`.\n\nOnce the files are downloaded and included in the autoload, run any library migrations\nto ensure the database is set up correctly:\n* `\u003e php spark migrate -all`\n\n`Preferences` suggests the Composer provision for `codeigniter4/authentication-implementation` as describe in the\n[CodeIgniter authentication guidelines](https://codeigniter4.github.io/CodeIgniter4/extending/authentication.html).\nWithout this each preference will be limited to the session duration so it is highly recommended\nyou install and configure a [supported package](https://packagist.org/providers/codeigniter4/authentication-implementation).\n\n## Usage\n\n`Preferences` requires [CodeIgniter Settings](https://github.com/codeigniter4/settings) so\nyou may use all the same classes and functions described in its documentation as well. To\naccess the user-specific context settings call the `preference()` function anywhere you would\nnormally use `setting()`:\n```php\nclass Home extends Controller\n{\n    public function index()\n    {\n        return view('welcome', [\n            'icon' =\u003e preference('Users.avatar'),\n        ];\n    }\n\n    public function update_avatar()\n    {\n        if ($icon = $this-\u003erequest-\u003egetPost('icon')) {\n            preference('Users.avatar', $icon);\n        }\n\n        return redirect()-\u003eback();\n    }\n}\n```\n\n\u003e Note: Be sure to load the helper file (`helper('preferences')`) before using the helper function.\n\n`preference()` will retrieve and store contextual settings for the current authenticated user.\nIf no user is authenticated then it will fall back on the `Session` class with semi-persistent\nsettings for as long as the session lasts.\n\n### Placeholder Config\n\nIn most cases each setting should have a corresponding Config file. Sometimes these settings\nwill not fit under an existing logical grouping, so this library provides a \"placeholder\"\nConfig (`Tatter\\Preferences\\Config\\Preferences`). You may add your own version in **app/* to\nsupply default values:\n```php\n\u003c?php\n\nnamespace Config;\n\nclass Preferences extends \\Tatter\\Preferences\\Config\\Preferences\n{\n    /**\n     * Slug for the current user theme.\n     */\n    public string $theme = 'midnight';\n}\n```\n\nAny function calls with the class unspecified will reference the `Preferences` class:\n```php\n// Identical calls:\n$theme = preference('Preferences.theme');\n$theme = preference('theme');\n```\n\n\u003e Hint: Don't forget that libraries and modules can provide Config properties via [Registrars](https://codeigniter.com/user_guide/general/configuration.html#registrars)\n\n## Troubleshooting\n\n`Preferences` is a very \"thin\" library conjoining `Settings` and your authentication library\nof choice. Most likely any issues are related to one of the underlying libraries and should\nbe directed there, but if you believe there is a problem or a feature request appropriate to\nthis repository then feel free to open an Issue or Pull Request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftattersoftware%2Fcodeigniter4-preferences","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftattersoftware%2Fcodeigniter4-preferences","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftattersoftware%2Fcodeigniter4-preferences/lists"}