enterprisephp/display-bundle

This Bundle provides generate view for given object

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

This package is not auto-updated.

Last update: 2024-11-19 19:42:53 UTC


README

Easily generate view for given entity/object

SensioLabsInsight knpbundles.com

Very Basic Screenshot;

image

Related Links;###

Installation

Step 1: Download the Bundle

Open a command console, go to your project directory and execute the following command to download the latest version of this bundle:

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

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

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

            new EP\DisplayBundle\EPDisplayBundle(),
        );

        // ...
    }

    // ...
}

DisplayTrait

use DisplayTrait on which you want to display objects/entities (!important):

namespace AppBundle\Entity;

use EP\DisplayBundle\Entity\DisplayTrait;

class MyEntity
{
    use DisplayTrait;
}

Configuration

Add below configs to config.yml file:

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

Usage

If you do not want to any extreme things. Only display on template;

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

You can override all bundle configs via class annotation:
related : 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
{

If you exclude spesific fields of entity use Exclude annotation:
related : 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;

Expose field. All fields defaultly exposes but if you excluded from config but only one time you want to expose this field;

namespace AppBundle\Entity;

use EP\DisplayBundle\Annotation as Display;

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

File expose with link;

namespace AppBundle\Entity;

use EP\DisplayBundle\Annotation as Display;

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

Image expose with img tag;

namespace AppBundle\Entity;

use EP\DisplayBundle\Annotation as Display;

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

You can spesify all configs from template as second param on display function;

{{ 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"
}) }}

Reporting an issue or a feature request

Issues and feature requests are tracked in the Github issue tracker.

When reporting a bug, it may be a good idea to reproduce it in a basic project built using the Symfony Standard Edition to allow developers of the bundle to reproduce the issue by simply cloning it and following some steps.