elao/admin-bundle

该包已被弃用且不再维护。未建议替代包。

简单、强大且可扩展的行政包。

安装: 541

依赖: 2

建议者: 0

安全性: 0

星标: 9

关注者: 17

分支: 1

开放问题: 6

类型:symfony-bundle

v1.1.0 2017-02-05 11:48 UTC

README

只需编写一次控制器,即可用于所有模型。

是什么?

AdminBundle 帮助您定义可重用的 动作,这些动作可以作为 路由控制器 定义为 任何 模型。

为什么?

当实现多个模型(如 CRUD 后端)的类似控制器行为时,AdminBundle 可提高您的生产力。

如何?

AdminBundle 将动作声明为抽象服务,为每个模型实例化并配置一个实例,并在 Symfony 路由器中注册相应的路由。

您只需说“我需要一个 listuser。”AdminBundle 就会注册一个 /users 路由,该路由运行一个配置为处理 User 模型的 ListAction 实例。

设计目标

AdminBundle 的目的是提高您的生产力,同时保持灵活性和可扩展性。

安装

Composer 中需要包

$ composer require elao/admin-bundle

在您的 AppKernel 中安装包

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        // ...
        new Elao\Bundle\AdminBundle\ElaoAdminBundle(),
    ];
}

在您的 routing.yml 配置文件中导入路由

// app/config/routing.yml
elao_admin_bundle:
    resource: "@ElaoAdminBundle/Resources/config/routing.yml"
    prefix:   / # You can prefix all actions here

用法

使用一组动作

或者 创建您自己的动作集

配置

在您的 config.yml 中配置一些动作

# app/config/config.yml
elao_admin:
    administrations:
        # Where 'name' is the name of the administration
        name:
            # Administration-level options (optional)
            foo: true
            # (required)
            actions:
                # Where 'alias' is the alias of the action
                alias:
                    # Where 'action_type' is a registered action type.
                    action_type:
                        # Every action has its own options

以下是一个使用 ElaoHtmlActionBundle 提供的一些动作的示例。

# app/config/config.yml
elao_admin:
    administrations:
        post: # The name of the administration (usualy, the model name)
            repository: app.repository.post # The repository to use to access the model
            actions:
                list:               # A "list" action,
                    html_list: ~    # that use default configuration for "html_list".

                create:             # A "create" action,
                    html_create:    # that use "html_create" and specify the form to use.
                        form: BlogBundle\Form\PostType

                update:             # A "update" action,
                    html_update:    # that use "html_update" and specify the form to use.
                        form: BlogBundle\Form\PostType

                read:               # A "read" action,
                    html_read: ~    # that use default configuration for "html_read".

                delete:             # A "delete" action,
                    html_delete:    # that use "html_delete" and adds a security restriction.
                        security: has_role('ROLE_ADMIN')

此配置将生成以下路由

名称 方法 方案 主机 路径
post_list GET ANY ANY /posts
post_create GET/POST ANY ANY /posts/new
post_update GET/POST ANY ANY /posts/{id}/edit
post_read GET ANY ANY /posts/{id}
post_delete GET/POST ANY ANY /posts/{id}/delete

配置详细

要获取您行政的完整详细信息和默认值,请运行

bin/console debug:config ElaoAdminBundle