tatter/preferences
Composer 安装命令:
composer require tatter/preferences
包简介
Persistent user-specific settings for CodeIgniter 4
README 文档
README
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:
composer require tatter/preferences
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():
class Home extends Controller { public function index() { return view('welcome', [ 'icon' => preference('Users.avatar'), ]; } public function update_avatar() { if ($icon = $this->request->getPost('icon')) { preference('Users.avatar', $icon); } return redirect()->back(); } }
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:
<?php namespace Config; class Preferences extends \Tatter\Preferences\Config\Preferences { /** * Slug for the current user theme. */ public string $theme = 'midnight'; }
Any function calls with the class unspecified will reference the Preferences class:
// Identical calls: $theme = preference('Preferences.theme'); $theme = preference('theme');
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.
tatter/preferences 适用场景与选型建议
tatter/preferences 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 47.91k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2021 年 11 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「codeigniter」 「Settings」 「preferences」 「codeigniter4」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tatter/preferences 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tatter/preferences 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tatter/preferences 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Persistent settings package for Laravel framework.
A Laravel Nova Tool to let users manage global settings created from code.
A Zend Framework module to quickly and easily set PHP settings.
The CodeIgniter Redis package
Lightweight settings management for CodeIgniter 4
Settings Card for Laravel Nova.
统计信息
- 总下载量: 47.91k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 19
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-11-19