jaclise / setting
为其他应用提供的 Yii2 设置
dev-develop
2016-03-04 13:47 UTC
Requires
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-09-14 18:26:13 UTC
README
为其他应用提供 Yii2 设置,特别是为 Yii2 Adminlte
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一
php composer.phar require funson86/yii2-setting "dev-master"
或添加
"funson86/yii2-setting": "*"
到您的 composer.json
文件的 require 部分。
使用
扩展安装后,只需在代码中通过以下方式使用它:
迁移
运行迁移
yii migrate --migrationPath=@funson86/setting/migrations
配置 /common/config/main.php 以使用 Yii::$app->setting
'components' => [ 'setting' => [ 'class' => 'funson86\setting\Setting', ], ],
在 backend/config/main.php 中配置后端模块以管理设置
'modules' => [ 'setting' => [ 'class' => 'funson86\setting\Module', 'controllerNamespace' => 'funson86\setting\controllers' ], ],
在后台配置
后端: http://you-domain/backend/web/setting
添加您的设置
设置支持三种类型的设置:文本、密码、选择。您可以通过迁移或手动插入到 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'), (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');