enterprisephp/display-bundle

此Bundle提供为给定对象生成视图的功能

v1.3 2017-03-29 06:44 UTC

This package is not auto-updated.

Last update: 2024-09-24 18:48:52 UTC


README

轻松为给定实体/对象生成视图

SensioLabsInsight knpbundles.com

非常基本的截图;

image

相关链接;###

安装

步骤1:下载Bundle

打开命令行,转到您的项目目录,并执行以下命令以下载此bundle的最新版本

$ composer require enterprisephp/display-bundle "dev-master"

此命令需要您全局安装Composer,如Composer文档中的安装章节所述。

步骤2:启用Bundle

然后,通过将其添加到项目中的app/AppKernel.php文件中注册的bundle列表来启用bundle

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new EP\DisplayBundle\EPDisplayBundle(),
        );

        // ...
    }

    // ...
}

DisplayTrait

在您想要显示对象/实体的地方使用DisplayTrait(非常重要)

namespace AppBundle\Entity;

use EP\DisplayBundle\Entity\DisplayTrait;

class MyEntity
{
    use DisplayTrait;
}

配置

将以下配置添加到config.yml文件中

ep_display:
    global:
        image_render: true # (optinal) defaults to true
        file_render: true # (optinal) defaults to true
        template: EPDisplayBundle::display.html.twig # (optinal) defaults to EPDisplayBundle:display.html.twig template
        exclude_vars: # (optinal) defaults to empty array
            - excludeField
            - hiddenField
            - password
        array_collection_render: true # (optinal) defaults to true
        collection_item_count: 5 # (optinal) defaults to 10

用法

如果您不想做任何极端的事情,仅显示在模板中;

{{ display(entity) }} # so easy isn't it 😉

您可以通过类注解覆盖所有bundle配置
相关: https://github.com/EnterprisePHP/EPDisplayBundle/blob/master/Annotation/Display.php#L11

namespace AppBundle\Entity;

use EP\DisplayBundle\Annotation as Display;

/**
 * @Display\Display(
 *     image_render=false, # optinal
 *     file_render=false, # optinal
 *     template="my_entity_special_template.html.twig", # optinal
 *     array_collection_render=true, # optinal
 *     collection_item_count=8, # optinal
 * )
 */
class MyEntity
{

如果您想排除实体的特定字段,请使用Exclude注解
相关: https://github.com/EnterprisePHP/EPDisplayBundle/blob/master/Annotation/Exclude.php

namespace AppBundle\Entity;

use EP\DisplayBundle\Annotation as Display;

class DummyEntity
{
  /**
   * @Display\Exclude
   */
  protected $unPublicfieldForOnlyThisEntity;

公开字段。所有字段默认公开,但如果您在配置中排除,但只想公开此字段一次;

namespace AppBundle\Entity;

use EP\DisplayBundle\Annotation as Display;

class DummyEntity
{
  /**
   * @Display\Expose
   */
  protected $oneTimeExposeField;

带有链接的文件公开;

namespace AppBundle\Entity;

use EP\DisplayBundle\Annotation as Display;

class DummyEntity
{
  /**
   * @Display\File(path="uploads/files")
   */
  protected $mainFile;

带有img标签的图像公开;

namespace AppBundle\Entity;

use EP\DisplayBundle\Annotation as Display;

class DummyEntity
{
  /**
   * @Display\Image(
   *    path="uploads/files",
   *    height="50",
   *    width="70",
   * )
   */
  protected $cover;

您可以在display函数的第二个参数上指定所有配置,从模板中;

{{ display(entity, {
    files: {
        my_file: {
            path: "web/uploads"
        }
    },
    images: {
        header: {
            path: "web/images",
            width: "70",
            height: "50"
        }
    },
    exclude: "myVeryPrivateField", // can be array
    expose: "onlyForThisPageExposeVar", // can be array
    image_render: true,
    file_render: true,
    array_collection_render: false,
    collection_item_count: 90,
    template: "my_stylish_template.html.twig"
}) }}

报告问题或功能请求

问题和功能请求在Github问题跟踪器中跟踪。

当报告一个错误时,最好在基本项目中重现它,该项目使用Symfony标准版构建,以便bundle的开发者可以通过简单地克隆它并遵循一些步骤来重现问题。