yiier/yii2-user-setting
Composer 安装命令:
composer require yiier/yii2-user-setting
包简介
User Settings For Yii2
关键字:
README 文档
README
User Settings For Yii2
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist yiier/yii2-user-setting "*"
or add
"yiier/yii2-user-setting": "*"
to the require section of your composer.json file.
Configuration
Database Migrations
Before usage this extension, we'll also need to prepare the database.
php yii migrate --migrationPath=@yiier/userSetting/migrations/
Module Setup
To access the module, you need to configure the modules array in your application configuration:
'modules' => [ 'userSetting' => [ 'class' => 'yiier\userSetting\Module', ], ],
Component Setup
To use the Setting Component, you need to configure the components array in your application configuration:
'components' => [ 'userSetting' => [ 'class' => 'yiier\userSetting\UserSetting', ], ],
Usage
<?php $setting = Yii::$app->userSetting; $value = $setting->get('key'); $value = $setting->get('key', Yii::$app->user->id); $setting->set('key', 125.5); $setting->set('key', 125.5, Yii::$app->user->id); $setting->set('key', false, Yii::$app->user->id, 'Not allowed Update Post'); $setting->set('key', false, 0, 'Not allowed Update Post'); // Checking existence of setting $setting->has('key'); $setting->has('key', Yii::$app->user->id); // Activates a setting $setting->activate('key'); $setting->activate('key', Yii::$app->user->id); // Deactivates a setting $setting->deactivate('key'); $setting->deactivate('key', Yii::$app->user->id); // Removes a setting $setting->remove('key'); $setting->remove('key', Yii::$app->user->id); // Removes all settings $setting->removeAll(); $setting->removeAll(Yii::$app->user->id); // Get's all values in the specific section. $setting->getAllByUserId(Yii::$app->user->id); $setting->invalidateCache(Yii::$app->user->id); // automatically called on set(), remove();
UserSettingAction
To use a custom settings form, you can use the included UserSettingAction.
- Create a model class with your validation rules.
- Create an associated view with an
ActiveFormcontaining all the settings you need. - Add
yiier\userSetting\UserSettingActionto the controller's actions.
The settings will be stored in section taken from the form name, with the key being the field name.
Model:
<?php class SiteForm extends Model { public $siteName, $siteDescription; public function rules() { return [ [['siteName', 'siteDescription'], 'string'], ]; } public function fields() { return ['siteName', 'siteDescription']; } public function attributes() { return ['siteName', 'siteDescription']; } public function attributeLabels() { return [ 'siteName' => 'Site Name', 'siteDescription' => 'Site Description' ]; } }
Views:
<?php $form = ActiveForm::begin(['id' => 'site-settings-form']); ?> <?= $form->field($model, 'siteName') ?> <?= $form->field($model, 'siteDescription') ?> <?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?> <?php ActiveForm::end(); ?>
Controller:
public function actions() { return [ //.... 'site-settings' => [ 'class' => UserSettingAction::class, 'modelClass' => 'app\models\SiteForm', //'scenario' => 'site', // Change if you want to re-use the model for multiple setting form. //'userId' => 0', // By default use \Yii::$app->user->id 'viewName' => 'site-settings', // The form we need to render 'successMessage' => '保存成功' ], //.... ]; }
Reference
yiier/yii2-user-setting 适用场景与选型建议
yiier/yii2-user-setting 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.96k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 07 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「extension」 「yii2」 「setting」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yiier/yii2-user-setting 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yiier/yii2-user-setting 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yiier/yii2-user-setting 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
An app setting manager tool for laravel nova
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
Persistent Laravel configuration settings.
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
UI Kit 3 Extension for Yii2
统计信息
- 总下载量: 1.96k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 12
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-4-Clause
- 更新时间: 2019-07-27