elao/html-action-bundle

为 elao/admin-bundle 提供的一套 HTML 动作。

安装: 191

依赖: 0

建议者: 1

安全: 0

星标: 0

关注者: 19

分支: 0

开放问题: 0

类型:symfony-bundle

v1.1.0 2017-02-05 13:15 UTC

This package is auto-updated.

Last update: 2024-09-05 18:59:39 UTC


README

此包提供了 CRUD + 列表动作,可与 ElaoAdminBundle 一起使用

安装

Composer 中要求此包

$ composer require elao/html-action-bundle

在您的 AppKernel 中安装此包

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        //...
        // ElaoHtmlActionBundle requires ElaoAdminBundle, you'll need to register it too.
        // new Elao\Bundle\ElaoAdminBundle\ElaoAdminBundle(),
        new Elao\Bundle\HtmlActionBundle\ElaoHtmlActionBundle(),
    );
}

## 配置

HtmlActionBundle 为 AdminBundle 提供了 5 个动作

  • html_list:模型列表。例如:“GET /posts”
  • html_create:创建表单及其 POST 处理程序。例如:“GET|POST /posts/new”
  • html_read:单个模型的详细信息。例如:“GET /posts/{id}”
  • html_update:单个模型的修改表单及其 POST 处理程序。例如:“GET|POST /posts/{id}/edit”
  • html_delete:单个模型的删除表单(请求用户确认)及其 POST 处理程序。例如:“GET|DELETE /posts/{id}/delete”

以下是定义“Post”实体简单 CRUD 管理的示例。

elao_admin:
    administrations:
        # Administration, named after the model, will impact urls and route names
        post:
            # The repository service for the Post model (usually DoctrineRepository for model "Post")
            repository: blog.repository.post
            # The list of actions
            actions:
                list:
                    # We're using default values for the list
                    html_list: ~
                create:
                    html_create:
                        # Specify the form type to use to create a Post
                        form: BlogBundle\Form\PostType
                update:
                    html_update:
                        # Specify the form type to use to edit a Post
                        form: BlogBundle\Form\PostType
                read:
                    # We're using default values for the read
                    html_read: ~
                delete:
                    html_delete:
                        # We're adding a security restriction on the delete action
                        security: has_role('ROLE_ADMIN')

不要忘记声明相应的存储库服务:(扩展 elao_admin.repository.doctrine/Elao\Bundle\AdminBundle\Service\DoctrineRepository 或使用您自己的 Elao\Bundle\AdminBundle\Behaviour\RepositoryInterface 实现)

# services.yml
blog.repository.post:
    parent: elao_admin.repository.doctrine
    arguments: ['BlogBundle\Entity\Post']

完整配置

列表

创建

读取

更新

删除

视图

请注意,此包不提供视图。您必须创建它们以显示不同的表单。

默认视图路径为 app/Resources/[name]/[alias].html.twig。您可以通过设置动作选项中的显式视图来覆盖此路径。

Doctrine 服务存储库(可选)

为了方便,您可以使用 AdminBundle 的 DoctrineRepository 作为默认的 doctrine 存储库。这样,Doctrine 实体管理器的 getRepository 方法将返回为每个模型声明的存储库服务。

要激活此功能

# config.yml
elao_admin:
    doctrine_service_repositories: true

doctrine:
    default_repository_class:  Elao\Bundle\AdminBundle\Service\DoctrineRepository
    repository_factory: elao_admin.repository_factory.doctrine