vtch-bundles / sonata-dto-admin-bundle
Symfony Sonata / 将 DTO 集成到 SonataAdminBundle 中
Requires
- php: ^7.2 || ^7.4 || ^8.0
- doctrine/collections: ^1.5
- sonata-project/admin-bundle: ^3.29
- symfony/doctrine-bridge: ^2.8 || ^3.2 || ^4.0
- symfony/framework-bundle: ^2.8 || ^3.2 || ^4.0
This package is not auto-updated.
Last update: 2024-09-24 16:46:51 UTC
README
替代 SonataDoctrineOrmAdminBundle 用于 Sonata 管理员的处理。此套餐允许在管理员中使用 DTOs。
例如,它可以用于在 Sonata 管理员中显示从 API(或任何非 Doctrine 的来源)获取的数据。
安装
可以使用 Composer 安装此套餐。
- 需要在 Composer 的配置中添加 vtech 仓库
"repositories": { "vtech": { "type": "composer", "url": "https://composer.vtech.fr" } }
- 然后输入以下命令
composer require vtech-bundles/sonata-dto-admin-bundle
使用
管理员配置
为了使用此套餐,必须将一个管理员在 Sonata 中声明为类型 dto
。以下是一个 yaml 配置示例
tags: - { name: sonata.admin, manager_type: dto, label: 'my_admin_label' }
此外,为了正常工作,必须创建一个实现接口 Vtech\Bundle\SonataDTOAdminBundle\Repository\AdminRepositoryInterface
的类来指示如何获取、保存和修改 DTO。这个“仓库”类必须在依赖注入中使用以下方式标记
tags: - { name: 'sonata.admin.dto_repository', class: 'My\Dto\Class' }
为了利用最新版本的 Symfony 的自动配置,还存在一个“订阅者”接口(Vtech\Bundle\SonataDTOAdminBundle\Repository\AdminRepositoryInterface
),以删除标签中的 class
参数。您只需在 services.yaml
文件中添加以下内容即可(对于 Symfony ^3.3)
_instanceof: Vtech\Bundle\SonataDTOAdminBundle\Repository\AdminRepositoryInterface: tags: [sonata.admin.dto_repository]
此套餐中还有 4 个可选接口
实现这些接口的类必须以与“仓库”相同的方式在依赖注入中声明
tags: # Pour Vtech\Bundle\SonataDTOAdminBundle\Admin\IdentifierNormalizerInterface - { name: 'sonata.admin.dto_identifier_normalizer', class: 'My\Dto\Class' } # Pour Vtech\Bundle\SonataDTOAdminBundle\Admin\IdentifierDenormalizerInterface - { name: 'sonata.admin.dto_identifier_denormalizer', class: 'My\Dto\Class' } # Pour Vtech\Bundle\SonataDTOAdminBundle\Admin\IdentifierDescriptorInterface - { name: 'sonata.admin.dto_identifier_descriptor', class: 'My\Dto\Class' }
可用过滤器列表
当管理员类型为 dto
时,它不能在 configureDatagridFilters
方法中使用 Sonata 的默认过滤器。它必须使用以下之一(或创建一个新的)
发布
要发布此套餐的新版本,只需在 GitLab 中创建一个新的标签,然后更新内置于 satis 中的仓库 在此地址。