eduardoledo/generic-admin-bundle

一个通用的、易于使用的Symfony2 CRUD生成器

安装: 21

依赖: 0

建议者: 0

安全: 0

星星: 0

关注者: 1

分支: 0

开放问题: 0

语言:JavaScript

类型:symfony-bundle

dev-master 2014-04-11 20:38 UTC

This package is not auto-updated.

Last update: 2024-09-28 15:08:22 UTC


README

一个通用的、易于使用的Symfony2 CRUD生成器

先决条件

此版本的包需要 FOSUserBundleMakerlabs PagerBundleStfalconTinymceBundle。如果没有找到,这两个包将自动安装。

安装

安装是一个快速的三步过程

  1. 使用composer下载GenericAdminBundle
  2. 启用包
  3. 创建你的控制器类
  4. 配置GenericAdminBundle
  5. 导入GenericAdminBundle路由

第1步:使用composer下载FOSUserBundle

在composer.json中添加GenericAdminBundle

{
    "require": {
        "eduardoledo/generic-admin-bundle": "*"
    }
}

现在运行以下命令告诉composer下载包

$ php composer.phar update eduardoledo/generic-admin-bundle

Composer会将包安装到项目中的vendor/eduardoledo目录。

第2步:启用包

在kernel中启用包

<?php
// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new Lomaswifi\AdminBundle\LomaswifiAdminBundle(),
    );
}

如果您之前没有安装FOSUserBundle、Makerlabs/PagerBundle或StfalconTinymceBundle,您还必须在kernel中启用它们,这看起来可能如下所示

<?php
// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new FOS\UserBundle\FOSUserBundle(),
        new MakerLabs\PagerBundle\MakerLabsPagerBundle(),
        new Stfalcon\Bundle\TinymceBundle\StfalconTinymceBundle(),
        new Lomaswifi\AdminBundle\LomaswifiAdminBundle(),
    );
}

注意:FOSUserBundle和Makerlabs/PagerBundle必须在GenericAdminBundle之前加载

第3步:创建控制器类

为了获得所有相应的路由和操作,您需要为每个希望具有CRUD的实体创建一个控制器类,扩展\Lomaswifi\AdminBundle\Entity\myController或其子类

<?php

namespace Acme\DemoBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

/**
 * @Route("/admin/users")
 */
class UsersController extends \Lomaswifi\AdminBundle\Entity\myController
{

    protected $section = 'user';    // The section name you used in the config.yml

}

第4步:配置GenericAdminBundle

您必须在config.yml中为每个实体添加一个部分

# app/config/config.yml
lomaswifi_admin:
    sections:
        user:
            title: Users                                        # Title shown in CRUD
            singular: user
            plural: users
            route_prefix: acme_demo_users                  # Route prefix
            entity: AcmeDemoBundle:User                         # Entity alias
            form_class: \Lomaswifi\BlogBundle\Form\PostType
            form_service: fos_user.registration.form
            fields:
                username:
                    name: username
                    label: username
                email:
                    name: email
                    label: Email

对于每个实体,您必须创建一个包含以下参数的部分

  • 标题:部分标题。
  • 单数:实体的单数名称
  • 复数:实体的复数名称
  • 路由前缀:控制器路由的前缀,由symfony根据命名空间生成,用于没有显式名称的路由。在此示例中,Acme\DemoBundle\Controller\UsersController::indexAction的路由前缀将是acme_demo_users_index,路由前缀将是acme_demo_users
  • 实体:实体别名
  • form_class/form_service:实体的完整类名或表单服务
  • 字段:一个数组,包含您希望在CRUD列表中显示的字段名称和标签

第5步:导入GenericAdminBundle路由

最后但同样重要的是,我们添加了使admin功能的基础路由

# app/config/routing.yml
lomaswifi_admin:
    resource: "@LomaswifiAdminBundle/Controller/"
    type:     annotation
    prefix:   /

下一步

如果一切顺利,您现在可以在http://your_server_url/admin测试GenericBundleAdmin。

享受