fg / config-bundle
数据库设置
dev-master
2015-08-15 11:16 UTC
Requires
- php: >=5.3.2
- symfony/framework-bundle: ~2.3
This package is not auto-updated.
Last update: 2024-09-14 18:27:17 UTC
README
此包帮助您存储应用层的设置。这些设置基于范围(如通用、用户组、用户)存储,以后可以从任何层访问。
一个例子
假设我们为数学课程预留了30个配额
{ "id": 1, "scope_group_type": "labs", "scope_by_id": 2, "section": "registration", "name": "quota", "value": 30, "created_at" : "2015-08-13 00:00:00", "updated_at" : "2015-08-13 00:00:00" }
- 安装
1.1 安装存储库
您可以通过 composer 安装。
composer require fg/config-bundle
或者将以下内容添加到 composer.json
的 require 部分:
"fg/config-bundle": "dev-master"
1.2 在 app/AppKernel.php 中启用 Bundle
public function registerBundles() { $bundles = array( // ... new Fg\Bundle\ConfigBundle\FgConfigBundle() ); // ... }
1.3 运行迁移
php app/console doctrine:schema:update --force
- 用法
2.1 创建新设置
有三种不同方式来创建新设置。
2.1.1 使用命令行界面 (CLI)
您可以通过在 cli 中运行 php app/console fg:config:create
命令来创建新设置。
2.1.2 调用 SettingService 的 create 方法
您可以通过调用先前传递给服务容器的 SettingService
的 create 方法来创建新设置。
$settingService = $this->get('fg_config.service.setting_service'); #create($name, $value, $scopeGroupType, $section, $scopeById = 0) $setting = $settingService->create('test', 'test', 'general', 'general')
2.1.3 使用网页用户界面
http://localhost/path/to/management/setting
2.2 访问
2.2.1 从控制器层访问
... $settingService = $this->get('fg_config.service.setting_service'); $settingObject = $settingService->getAllSettingByScope('quota', 'labs', 'registration', 2); ...
2.2.2 从 Twig 访问
... {{ get_setting('phone') }} //get setting object of name phone {{ get_setting_value('phone') }} //get value of name phone ...