ewll / crud-bundle
Crud Bundle
2.0.1
2020-11-19 11:13 UTC
Requires
- php: ^7.3
- ext-json: *
- symfony/form: ^5
- symfony/framework-bundle: ^5
- symfony/translation: ^5
- symfony/validator: ^5
README
安装
composer require ewll/crud-bundle
添加到包配置
config/bundles.php
...
Ewll\CrudBundle\EwllCrudBundle::class => ['all' => true]`
...
config/routes.yaml
ewll_crud:
resource: '@EwllCrudBundle/Resources/config/routing.yaml'
prefix: '/crud'
单元
Ewll\CrudBundle\Unit\UnitInterface
public function setUserProvider(UserProviderInterface $userProvider): void
此函数允许在单元中注入获取用户的机制。
public function getUnitName(): string
主URL名称。必须在所有其他单元中唯一。
public function getEntityClass(): string
主实体类。
public function getSourceClassName(): string
实现 Ewll\CrudBundle\Source\SourceInterface 的类的类名,允许访问实体存储。
public function getAccessRuleClassName(): ?string
ewll/user-bundle 的 AccessRule 类的类名,实现了 Ewll\UserBundle\AccessRule\AccessRuleInterface。
public function getAccessConditions(string $action): array
必须返回一个 访问条件 数组。
public function getCustomActions(): array
必须返回一个 自定义操作 类名数组。
Ewll\CrudBundle\Unit\CreateMethodInterface
允许通过请求创建实体:POST /crud/{unitName}
public function getCreateFormConfig(): FormConfig
为实体创建设置 表单配置。
public function getMutationsOnCreate(object $entity): array
返回包含新值的字段数组。在存储之前调用此方法。
public function onCreate(object $entity, array $formData): void
INSERT 事务中的一些动作。
public function getCreateExtraData(object $entity): array
一些您需要在创建成功后看到的响应中的数据。
Ewll\CrudBundle\Unit\UpdateeMethodInterface
Ewll\CrudBundle\Unit\ReadMethodInterface
Ewll\CrudBundle\Unit\DeleteMethodInterface
访问条件
@TODO
自定义操作
@TODO
表单配置
Ewll\CrudBundle\Form\FormConfig
这是对 Symfony 表单构建 的一些包装。
读取转换器
使用读取转换器将数据转换为视图。
- 您可以使用我们来自
Ewll\CrudBundle\ReadViewCompiler\Transformer
的常用读取转换器。 - 或创建自己的
为了创建转换器,您需要在App\Crud\Transformer
中创建两个类。
- 实现
Ewll\CrudBundle\ReadViewCompiler\Transformer\ViewTransformerInitializerInterface
。使用抽象类Ewll\CrudBundle\ReadViewCompiler\Transformer\ViewTransformerInitializerInterface
。此类用于定义转换器参数。您将其放入单元方法getReadListFields()
和getReadOneFields()
中。 - 实现
Ewll\CrudBundle\ReadViewCompiler\Transformer\ViewTransformerInterface
。将其作为带有标签crud_view_transformer
的服务。