simonduflos/dufadminbundle

Symfony 3 的管理组件包

安装: 34

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

语言:JavaScript

类型:symfony-bundle

dev-master 2017-10-16 10:17 UTC

This package is not auto-updated.

Last update: 2024-09-28 20:20:00 UTC


README

- WARNING : this bundle is still under development. You should not use it in production environment

该组件包的目的是提供一种快速的方式来实现一个完整功能的管理面板,并快速自定义管理面板,避免手动生成CRUD(创建、读取、更新、删除)和文件的多重复制。创建你的实体,设置一些注释和配置变量,你就可以在你的管理面板中获得一个动态的CRUD。

此组件包还附带了一系列内置功能:消息系统、文件管理器、多语言支持、网站地图生成、Redmine集成...

安装

simonduflos/dufadminbundle 添加到你的 composer.json

"require": {
	"simonduflos/dufadminbundle":"dev-master"
}

运行 composer.phar update 以安装组件包及其依赖项。

然后,将 DufAdminBundle 及其依赖项添加到你的 AppKernel.php

// app/AppKernel.php

public function registerBundles()
{
	$bundles = [
		// your other bundles

        new Braincrafted\Bundle\BootstrapBundle\BraincraftedBootstrapBundle(),
        new Bmatzner\FontAwesomeBundle\BmatznerFontAwesomeBundle(),
        new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
        new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
        new Lexik\Bundle\TranslationBundle\LexikTranslationBundle(),
        new HWI\Bundle\OAuthBundle\HWIOAuthBundle(),
        new Symfony\Bundle\AsseticBundle\AsseticBundle(),
        new Duf\AdminBundle\DufAdminBundle(),
        new Duf\CoreBundle\DufCoreBundle(),
        new Duf\MessagingBundle\DufMessagingBundle(),
        new Duf\ECommerceBundle\DufECommerceBundle(),
        new Duf\AggregatorBundle\DufAggregatorBundle(),
	];

    if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
        // your other test bundles
        
        $bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
    }
}

为了使用 BraincraftedBootstrapBundle,你必须安装一个LESS编译器,使用以下命令。如果在这一步遇到问题,请参考组件包的文档

	npm install -g less

然后,将以下配置添加到你的项目中

# app/config/config.yml

imports:
    - { resource: "@DufAdminBundle/Resources/config/config.yml" }
# app/config/routing.yml

duf_admin:
    resource: "@DufAdminBundle/Resources/config/routing.yml"
    prefix:   /site-admin
# app/config/security.yml
security:
    encoders:
        Symfony\Component\Security\Core\User\User:
            algorithm: plaintext
        Duf\AdminBundle\Model\DufAdminUserInterface:
            id: duf_admin.dufadminencoder
    providers:
        duf_admin_provider:
            entity: { class: Duf\AdminBundle\Entity\User }
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        duf_admin:
            provider: duf_admin_provider
            anonymous: ~
            form_login:
                login_path: duf_admin_login
                check_path: duf_admin_login_check
                always_use_default_target_path: true
                default_target_path: /site-admin
            logout:
                path: duf_admin_logout
                target: duf_admin_homepage
        duf_oauth:
            provider: duf_admin_provider
            anonymous: ~
            oauth:
                resource_owners:
                    facebook:           facebook_login
                login_path:        /oauth/login
                use_forward:       false
                failure_path:      /oauth/login
                oauth_user_provider:
                    oauth: hwi_oauth.user.provider.entity
        main:
            anonymous: ~
    access_control:
        - { path: ^/site-admin/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/site-admin, roles: ROLE_ADMIN }

最后,使用CLI运行 dufadminbundle:install

	php bin/console dufadmin:install

这将

  • 更新数据库模式
  • 创建 ROLE_ADMINROLE_USER
  • 创建具有 ROLE_ADMIN 权限的 User 实体
  • 创建默认语言
  • 导入组件包的本地化翻译
  • 安装资源
  • 导出资源

配置

为了自定义此组件包,你必须在 config.yml 文件中设置一些基本信息

# app/config/config.yml

duf_admin:
    site_name: "My website"                 # the name of your website
    upload_dir: "uploads/"                  # directory used by the file manager
    allowed_upload_extensions:              # extensions accepted by the file manager
        images:
            - jpg
            - png
        documents:
            - txt
            - pdf
        videos:
            - avi
            - mp4
    file_system_items_per_page: 4           # number of items to display in the file manager
    user_entity: "MyBundle:User"            # your User entity
    user_role_entity: "MyBundle:UserRole"   # your UserRole entity
    language_entity: "MyBundle:Language"    # your language entity

使用方法

  • 动态为实体生成CRUD

首先,将以下内容添加到你的配置中

duf_admin:
    entities:
        'AppBundle:MyEntity':
            title: 'My Entity'
            icon: 'fa-newspaper-o'
            title_field: 'title'

然后,在 /src/AppBundle/Entity/MyEntity.php 中配置你的实体以构建CRUD

导入这些注释

use Duf\AdminBundle\Entity\DufAdminEntity;
use Duf\AdminBundle\Annotations\IndexableAnnotation as Indexable;
use Duf\AdminBundle\Annotations\EditableAnnotation as Editable;

你的 MyEntity 类必须扩展 DufAdminEntity

从你的实体中删除 $id 属性,因为 DufAdminEntity 已经包含了该属性。

class MyEntity extends DufAdminEntity
{

}

为你的实体属性添加注释

/**
 * @var string
 *
 * @ORM\Column(name="title", type="string", length=255)
 * @Indexable(index_column=true, index_column_name="Title")
 * @Editable(is_editable=true, label="Title", required=true, type="text", order=1, placeholder="Write your title")
 */
private $title;

就是这样!如果你去 my-domain/site-admin,你应该在左侧边栏的“内容”部分看到一个以你的实体命名的菜单项。

Indexable 注解指定了CRUD的“列表”部分中要包含哪些属性。

Editable 注解指定了CRUD的“创建/编辑”表单中要包含哪些属性。