Add Symfony2 ParamConverter and FormType to StaticEntity

Installs: 140

Dependents: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type: symfony-bundle

3.0.0 2015-11-10 13:29 UTC


This bundle brings ParamConverter and FormType supports to Symfony 2 for the StaticEntity library.

If you just need to use StaticEntity, and don't need the FormType and ParamConverter support, then this bundle is NOT required.

You can use StaticEntity in your project like any other library.

This 2.x branch supports SensioFrameworkBundle 3.x (Used by Symfony 2.4+)

For support of SensioFrameworkBundle 2.x (Used by Symfony 2.3), use the 1.x branch


Add the package in your composer.json

At command line, run composer require byscripts/static-entity-bundle:~2.0

Enable the Bundle

Add Byscripts\Bundle\StaticEntityBundle\ByscriptsStaticEntityBundle to the app/AppKernel.php file.


Create a static entity

First, create a static entity on your project (for example, in src/YourVendorName/YourBundle/StaticEntity)


namespace YourVendorName\YourBundle\StaticEntity;

use Byscripts\StaticEntity\StaticEntity;

class Civility extends StaticEntity
    private $name;
    private $shortName;

    public static function getDataSet()
        return array(
            'mr' => array('name' => 'Mister', 'shortName' => 'Mr'),
            'mrs' => array('name' => 'Misses', 'shortName' => 'Mrs'),

For more details on usage of Static Entities, look at StaticEntity

Use the FormType

$builder->add('civility', 'static_entity', $parameters);
List of parameters

| class | required | FQCN of the static entity | null | | function | optional | The function to use to get SE instances | getAll | | property | optional | The instance property to use as label | name | | group_by | optional | The instance property to use to group labels | null |

static_entity type extends the native choice type and can use any of its options.

Use the ParamConverter

class MyController
    public function myAction(Civility $civility)
        $name = $civility->getName();

Nothing else to do.