PHPackages                             20steps/autotables-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. 20steps/autotables-bundle

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

20steps/autotables-bundle
=========================

Symfony bundle for mapping entities into auto generated tables

v1.0.2(9y ago)21.1k[1 issues](https://github.com/20steps/autotables-bundle/issues)LGPL-3.0+JavaScript

Since Dec 15Pushed 9y ago2 watchersCompare

[ Source](https://github.com/20steps/autotables-bundle)[ Packagist](https://packagist.org/packages/20steps/autotables-bundle)[ Docs](https://github.com/20steps/autotables-bundle)[ RSS](/packages/20steps-autotables-bundle/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (4)Versions (4)Used By (0)

20steps/autotables-bundle (twentystepsAutoTablesBundle)
=======================================================

[](#20stepsautotables-bundle-twentystepsautotablesbundle)

[![Dependency Status](https://camo.githubusercontent.com/963e81a1cc9f64f40316082a56e91c9f8aa4c7f3cb0df45d19597186cb25d573/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3538353433613565383166666463303034313166313562652f62616467652e7376673f7374796c653d666c61742d737175617265)](https://www.versioneye.com/user/projects/58543a5e81ffdc00411f15be)[![Packagist version](https://camo.githubusercontent.com/ba3b4a2ff74346fb6cf5c5fe1a01cfa5e60817013ee407601518807ae083c5de/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f323073746570732f6175746f7461626c65732d62756e646c652e737667)](https://packagist.org/packages/20steps/autotables-bundle)

About
-----

[](#about)

The 20steps AutoTables Bundle provides an easy way for displaying entities in Symfony2 applications in auto-generated and editable tables. The tables are rendered by [DataTables](https://datatables.net/) and are made editable with a patched version of [jquery.datatables.editable](https://code.google.com/p/jquery-datatables-editable/).

The AutoTables Bundle is licensed under the LGPL license version 3.0 ().

Features
--------

[](#features)

- Visualization of custom entities in auto-generated tables
- Updating, removing and adding entities
- Integration of Doctrine repositories
- Integration of custom CRUD services
- Annotating entities with Doctrine annotations
- Annotating entities with AutoTablesBundle annotations
- Displaying columns of either properties or methods
- Modifying columns for either properties or methods
- Declaring columns as read-only
- Auto-initialization feature for newly added entities supporting constant values and ManyToOne-Mappings
- JQuery-UI and Bootstrap3 support
- Many customization options

Installation
------------

[](#installation)

Require the bundle by adding the following entry to the respective section of your composer.json:

```
"20steps/autotables-bundle": "dev-master"

```

Get the bundle via packagist from GitHub by calling:

```
php composer.phar update 20steps/autotables-bundle

```

Register the bundle in your application by adding the following line to the registerBundles() method of your AppKernel.php:

```
new twentysteps\Bundle\AutoTablesBundle\twentystepsAutoTablesBundle()

```

Add the bundle to your assetic configuration in config.yml:

```
assetic:
    bundles:        [ 'twentystepsAutoTablesBundle' ]

```

Add the bundle's routes to your routing.yml

```
twentysteps_auto_tables:
    resource: "@twentystepsAutoTablesBundle/Resources/config/routing.yml"
    prefix:   /autoTables

```

Usage
-----

[](#usage)

The following sections describe how to integrate the auto-generated tables in your application. As a prerequisite the steps of the Installation section has to be done.

### Global configuration

[](#global-configuration)

The bundle is configured in your config.yml with a section named twentysteps\_auto\_tables:

```
twentysteps_auto_tables:
    ...

```

Possible global configuration options are:

- default\_datatables\_options: Default configuration of the [DataTables](https://datatables.net/) plugin. It is given by a string containing a JSON representation of the options. Any settings given here will be extended by table specific options.
- trans\_scope: Default scope for autotables related translations.
- frontend\_framework: Frontend framework to be used for rendering. Currently the values "jquery-ui" (the default) and "bootstrap3" are supported.

```
twentysteps_auto_tables:
    default_datatables_options: >
    {
      "sDom": "TCt"
    }
    trans_scope: 'autoTableMessages'

```

### Table specific configuration

[](#table-specific-configuration)

Now the tables to be rendered by the bundle has to be configured. This happens as a list in a *tables* section. Each table configuration has to have an *id* property. This is used to reference the configurations in later calls to the bundle.

#### repository and service

[](#repository-and-service)

Additionally each table configuration has to define either a *repository* or a *service*. The *repository* is the name of a Doctrine repository for handling the entities to be printed. If you are not using Doctrine (or for some other reason) you can define a *service* pointing to a service implementing the AutoTablesCrudService interface.

#### trans\_scope

[](#trans_scope)

With the property *trans\_scope* you can define a new scope for translating the messages used for the table. These are the names of the columns and some additional messages like found in the messages.en.yml file of the bundle. By default the value from the global configuration is used.

#### datatable\_options

[](#datatable_options)

The property *datatables\_options* may be used to give some table specific [DataTables](https://datatables.net/) plugin configuration, which will extend any configuration in the global section.

#### views

[](#views)

The *views* option may point to a directory with custom templates for overwriting the ones of the bundle.

#### columns

[](#columns)

With *columns* you are able to overwrite any setting done by an autotables annotation resp. you are able to define settings that hasn't been configured by an annotation. Any column setting in the config.yml overwrites any annotation.

Currently the following things may be configured for a column: *name*, *readOnly*, *type*, *order* and *ignore*.

The parameter *selector* has to be given to select the column to be overwritten. This may be a property like *description*, or a method like *getDisplayName()*.

For columns that should be auto initialized while using the add entry form, you may configure an *initializer* section. This section may contain the values *repository*, *value* and *id*.

The property *value* simply selects a constant value to be injected into each new entity with this column. By selecting a repository one is able to inject an object found by a given id. The id may be passed by a constant value here in the config.xml or later in the Twig view while using the function *ts\_auto\_table\_options*.

#### Example

[](#example)

Here is an example of a configuration given for a table *products*:

```
twentysteps_auto_tables:
  default_datatables_options: >
    {
      "sDom": "TCt"
    }
  tables:
    -
      id: "products"
      repository: 'AcmeStoreBundle:Product'
      trans_scope: 'autoTables'
      datatables_options: >
        {
          "oLanguage": {
            "sLengthMenu": "_MENU_ entries per page",
            "sSearch": "Search",
            "oTableTools": {
                "aButtons": [
                  {"sExtends": "copy", "sButtonText": "Copy"},
                ]
            }
          }
        }
      columns:
              -
                selector: 'description'
                readOnly: true
                order: 2
              -
                selector: 'client'
                visible: false
                initializer:
                    repository: 'AcmeStoreBundle:Client'
              -
                selector: 'getDisplayName()'
                order: 10
                readOnly: false

```

### Annotation of entities

[](#annotation-of-entities)

The information needed to render any column into a table is taken from annotations found in the entity. The bundle searches for Doctrine annotations like *@Doctrine\\ORM\\Mapping\\Column* and *@Doctrine\\ORM\\Mapping\\Id*. If you want to give a different name, set an order value or for some other reason you can use the bundle's annotation *twentysteps\\Bundle\\AutoTablesBundle\\Annotations\\Column*. Even getter methods may be annotated with this annotation, to create a column displaying the value returned by the getter. To be able to update the value in this case, a setter of the same name has to be created (getFoo/setFoo). It's even possible to disable the editing of a column by using the *readOnly* property of the annotation.

If you want to avoid rendering the column in the auto generated table, you should set the *ignore* flag of the annotation to true. In this case the property resp. method is ignored by the bundle.

Like mentioned in the configuration section, any column may be initialized automatically while using the add entry form. This may be configured with the *Initializer* annotation like described in the configuration section or shown in the following examples:

```
/**
 * @ORM\ManyToOne(targetEntity="Client", inversedBy="products")
 * @ORM\JoinColumn(name="client_id", referencedColumnName="id")
 * @AUT\Column(type="mixed", visible=false, initializer=@AUT\Initializer(repository="AcmeStoreBundle:Client"))
 */
private $client;

/**
 * @ORM\Column(type="string", length=100)
 * @AUT\Column(visible=false, initializer=@AUT\Initializer(value="bar"))
 */
private $foo;

```

The following code block shows a complete example of a properly annotated entity for AutoTablesBundle:

```
