dhorchler/config-bundle

此包已被废弃且不再维护。未建议替代包。

存储在数据库中的设置,可在Sonata Admin Bundle中进行管理。

安装: 70

依赖者: 0

建议者: 0

安全: 0

星标: 1

关注者: 2

分支: 2

开放问题: 2

类型:symfony-bundle

dev-master 2014-11-22 15:57 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:24:07 UTC


README

#信息

兼容Symfony 2.5(建设中)

DHorchlerConfigBundle 将配置设置存储在ORM数据库中,并在Sonata Admin Bundle中使它们可管理。这些设置可以在项目的任何地方使用,并且可以通过Sonata管理员用户在运行时进行修改。

#特性

  • 对不同的数据类型进行单独验证
  • 易于自定义的错误文本的单独约束
  • 支持jQuery表单字段默认值

###当前支持的数据类型:字符串、整数、浮点数、日期、日期时间、选择、多选。

#安装

##获取包

首先将其添加到composer.json中,然后通过Composer下载和安装包

{
    "require": {
        "dhorchler/config-bundle": "dev-master"
    }
}

然后运行

php composer.phar update dhorchler/config-bundle

##在app/AppKernel.php中启用包

public function registerBundles() {
    $bundles = array(
        // ...
        new DHorchler\ConfigBundle\DHorchlerConfigBundle(),
    );
    // ...
}

##创建设置表

您可以通过以下方式执行此操作:

php app/console doctrine:migrations:diff
php app/console doctrine:migrations:migrate

php app/console doctrine:schema:update

或您喜欢的任何方式。

#配置

在app/config/config.yml中添加

sonata_block:
    default_contexts: [cms]
    blocks:
        sonata.admin.block.admin_list:
            contexts:   [admin]
        sonata.block.service.text:
        sonata.block.service.rss:

sonata_admin:
    title:      Sonata Project
    title_logo: /bundles/sonataadmin/logo_title.png
    templates:
        layout:  SonataAdminBundle::standard_layout.html.twig
        ajax:    SonataAdminBundle::ajax_layout.html.twig
        list:    SonataAdminBundle:CRUD:list.html.twig
        show:    SonataAdminBundle:CRUD:show.html.twig
        edit:    DHorchlerConfigBundle::edit.html.twig
    dashboard:
        blocks:
            - { position: left, type: sonata.admin.block.admin_list }
            
services:
      sonata.dh.admin.settings:
        class: DHorchler\ConfigBundle\Admin\ConfigAdmin
        tags:
            - { name: sonata.admin, manager_type: orm, group: 'settings', label: Settings }
        arguments:
            - null
            - DHorchler\ConfigBundle\Entity\Settings
            - DHorchlerConfigBundle:Admin

完成所有这些后,从Sonata Admin后端开始管理您的设置。

#使用示例

$this->em = $this->getDoctrine()->getEntityManager();
$settingsRaw = $this->em->createQueryBuilder()
    ->select('s.name, s.currentValue')
    ->from('DHorchlerConfigBundle:Settings', 's')
    ->getQuery()
    ->getResult();
foreach ($settingsRaw AS $setting) $settings[$setting['name']] = $setting['currentValue']

#预览

Screen shot list settings

Screen shot edit integer settings

Screen shot edit date settings

#待办事项

  • 添加更多测试
  • 客户端验证