itzen / yii2-setting
适用于其他应用的Yii2 Setting
dev-master
2016-01-10 22:47 UTC
Requires
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-09-24 16:35:19 UTC
README
适用于其他应用的Yii2 Setting,尤其是适用于 Yii2 Adminlte
安装
安装此扩展的首选方式是通过 composer。
运行以下命令
php composer.phar require itzen/yii2-setting "dev-master"
或者在您的 composer.json
文件的 require 部分添加
"itzen/yii2-setting": "*"
使用方法
安装扩展后,只需在您的代码中使用它即可
迁移
迁移执行
yii migrate --migrationPath=@itzen/setting/migrations
配置 /common/config/main.php 以使用 Yii::$app->setting
'components' => [ 'setting' => [ 'class' => 'itzen\setting\Setting', ], ],
在 backend/config/main.php 中配置后端模块以管理设置
'modules' => [ 'setting' => [ 'class' => 'itzen\setting\Module', 'controllerNamespace' => 'itzen\setting\controllers' ], ],
在后台配置
后端: http://you-domain/backend/web/setting
添加您的设置
设置支持 3 种类型的设置:文本、密码、选择。您可以通过迁移或手动插入到 setting
表中添加您的设置。
INSERT INTO `setting` (`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`) VALUES (11, 0, 'info', 'group', '', '', '', '50'), (21, 0, 'basic', 'group', '', '', '', '50'), (31, 0, 'smtp', 'group', '', '', '', '50'), (1111, 11, 'siteName', 'text', '', '', 'Your Site', '50'), (1112, 11, 'siteTitle', 'text', '', '', 'Your Site Title', '50'), (1113, 11, 'siteKeyword', 'text', '', '', 'Your Site Keyword', '50'), (1114, 11, 'someText', 'redactor', '<div class=\"label\">Some clip</div>|<div>Another clip for redactor</div>', '', '', '50'); // it will generate redactor wysywig (2111, 21, 'timezone', 'select', '-12,-11,-10,-9,-8,-7,-6,-5,-4,-3.5,-3,-2,-1,0,1,2,3,3.5,4,4.5,5,5.5,5.75,6,6.5,7,8,9,9.5,10,11,12', '', '8', '50'), (2112, 21, 'commentCheck', 'select', '0,1', '', '1', '50'), (3111, 31, 'smtpHost', 'text', '', '', 'localhost', '50'), (3112, 31, 'smtpPort', 'text', '', '', '', '50'), (3113, 31, 'smtpUser', 'text', '', '', '', '50'), (3114, 31, 'smtpPassword', 'password', '', '', '', '50'), (3115, 31, 'smtpMail', 'text', '', '', '', '50');
使用您的设置
在后台设置值后。只需通过以下代码访问您的设置
echo Yii::$app->setting->get('siteName');