certunlp / database-config-bundle
允许从数据库管理Symfony容器的配置
dev-master
2020-09-17 19:52 UTC
Requires
- symfony/symfony: 3.4.*
This package is auto-updated.
Last update: 2024-09-18 04:52:25 UTC
README
注意! 此包之前称为FlexyDatabaseConfigBundle。请确保更新您的composer.json项目文件以反映名称更改。
UnifikDatabaseConfigBundle 允许您将包的配置树和参数存储在数据库表中。这些配置和参数将覆盖在 app/config/config.yml 和 app/config/parameters.yml 文件中定义的配置。
配置全部使用Symfony的容器缓存机制进行缓存,不直接访问数据库。
内容
- 安装
- 如何使用
安装
- 将以下内容添加到您的composer.json 中
"require": { "unifik/database-config-bundle": "dev-master" }
- 运行 composer update
composer update
- 在 AppKernel.php 中注册此包
public function registerBundles() { new Unifik\DatabaseConfigBundle\UnifikDatabaseConfigBundle(), }
- 在 AppKernel.php 中扩展 getContainerBuilder() 方法
use Unifik\DatabaseConfigBundle\DependencyInjection\Compiler\ContainerBuilder; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; ... protected function getContainerBuilder() { return new ContainerBuilder(new ParameterBag($this->getKernelParameters())); }
- 更新数据库模式
app/console doctrine:schema:update --force
如何使用
将配置添加到数据库
UnifikDatabaseConfigBundle 在名为 container_config 的数据库表中复现包的配置树。如果您想在数据库表中添加配置,您必须首先在 container_extension 表中添加扩展名。之后,您必须添加配置树中指向您需要覆盖的配置的每个父节点。
例如,如果您有以下配置并想覆盖 project_title
twig: globals: project_title: My project title
首先,我们必须在 container_extension 表中添加 twig
然后,我们在 container_config 表中添加指向 project_title 的每个节点
将参数添加到数据库
参数存储在数据库中的 container_parameter 表中。要将参数添加到数据库,您只需将它的名称和值添加到表中。
清除缓存
由于数据库配置和参数被缓存,每次您希望重新加载来自数据库的配置时,都需要执行 app/console cache:clear。