itk-dev/config-bundle

用于处理应用程序配置的Symfony包

3.0.0 2019-01-10 16:08 UTC

This package is auto-updated.

Last update: 2024-09-19 15:25:16 UTC


README

安装

composer require itk-dev/settings-bundle "^1.0"

app/AppKernel.php中启用该包

public function registerBundles() {
	$bundles = [
		// …
        // Start of required dependencies of ItkDevConfigBundle
        new Craue\ConfigBundle\CraueConfigBundle(),
        new EasyCorp\Bundle\EasyAdminBundle\EasyAdminBundle(),
        // End of required dependencies for ItkDevConfigBundle
        new ItkDev\ConfigBundle\ItkDevConfigBundle(),
	];
    // …
}

app/config/config.yml

craue_config:
    entity_name: ItkDev\ConfigBundle\Entity\Setting

# Optionally, enable caching for craue/config-bundle (cf. https://github.com/craue/CraueConfigBundle/#enable-caching-optional)
services:
  craue_config_cache_provider:
    class: Symfony\Component\Cache\Adapter\FilesystemAdapter
    public: false
    arguments:
      - 'craue_config'
      - 0
      - '%kernel.cache_dir%'

根据您的Doctrine设置,您可能需要将ItkDevConfigBundle添加到您的Doctrine映射中,例如:

doctrine:
    orm:
        entity_managers:
            default:
                mappings:
                    
                    ItkDevConfigBundle: ~

如果您使用Doctrine迁移,则应该从迁移中过滤掉craue_config_setting

doctrine:
    dbal:
        [...]
        schema_filter: ~^(?!craue_config_setting)~

使用方法

在数据库中创建设置(最好使用迁移)

insert into
    itkdev_setting(section, name, type, form_type, value_string)
values
    ('cms', 'about_header', 'string', 'text', 'About this application');

insert into
    itkdev_setting(section, name, type, form_type, value_text)
values
    ('cms', 'about, 'text', 'text', 'This application handles configuration on the database.);

Easy admin

查看Resources/config/easy_admin.yml以获取设置示例Easy Admin配置。

Twig

请参阅https://github.com/craue/CraueConfigBundle/#usage-in-twig-templates

富文本

要使用表单类型ckeditor,您必须启用IvoryCKEditorBundle(已安装)。

按照https://symfony.ac.cn/doc/master/bundles/EasyAdminBundle/integration/ivoryckeditorbundle.html#installing-the-rich-text-editor中的2-4步骤启用包。