Symfony: Admin Generator

The Admin Generator can be used to generate CRUD forms. You can create all the functionality of an admin site, including:

  • Generate Views and Controllers for Models with one command
  • Configure all options in one (per model) YAML file
  • Includes standard actions: create/edit, show, delete, list/nestedset tree list
  • Flexible and extendable: you can easily add or overwrite almost everything!
  • Supports most popular model managers: Doctrine ORM, Doctrine ORM and Propel
  • Introduces nested forms: create / edit object and all it’s associated objects in one form
  • Manage relations one to one, one to many, many to one and many to many
  • Fully translatable: all field elements (labels, placeholders, helpers), all widgets, actions, error messages and titles
  • List features: sortable, paginated, filters, batch actions, scopes
  • Nestedset tree list features: drag&drop to manage your tree
  • New / Edit featues: fieldsets, tabbable, cool widgets for collection, file upload, date and entity fields
  • Translated into DE, EN, ES, FA, FR, GR, IT, JA, NL, PL, PT, RO, RU, SL, TR, UK
  • Credentials for actions, columns and form fields
  • Complete admin design based on twitter bootstrap

Installation

Add Admingenerator to your composer.json. Note: with Doctrine, you’ll also have to setup the Doctrine2FixtureBundle bundle:

"require": {
    "cedriclombardot/admingenerator-generator-bundle": "2.3.*@dev",
    "knplabs/knp-menu": "2.0.*@dev",
    "knplabs/knp-menu-bundle":"2.0.*@dev",
    "doctrine/doctrine-fixtures-bundle": "2.2.*",
    "jms/security-extra-bundle": "1.5.*@dev"
},
"config": {
    "component-dir": "web/components" 
},

Install Composer curl -sS https://getcomposer.org/installer | php. Run php composer.phar update. Admingenerator has a dependency on KnpMenuBundle and WhiteOctroberPagerfantaBundle. Enable Admingenerator and its dependencies in your app/AppKernel.php:

<?php 
public function registerBundles()
{
    $bundles = array(
        // ...
        new Admingenerator\GeneratorBundle\AdmingeneratorGeneratorBundle(),
        new Knp\Bundle\MenuBundle\KnpMenuBundle(),
        new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
        new JMS\AopBundle\JMSAopBundle(),
        new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
        new JMS\DiExtraBundle\JMSDiExtraBundle($this)
    );
}

Assetic combines two major ideas: assets and filters. The assets are files such as CSS, JavaScript and image files. The filters are things that can be applied to these files before they are served to the browser. This allows a separation between the asset files stored in the application and the files actually presented to the user.

Choose your model manager and choose basic admingenerator template add following lines to app/config/config.yml:

admingenerator_generator:
    # choose  and enable at least one
    use_propel:           true
    use_doctrine_orm:     true
    use_doctrine_odm:     false
 
    # choose and uncomment only one first is with assetic, second is without
    # base_admin_template: AdmingeneratorGeneratorBundle::base_admin.html.twig
    # base_admin_template: AdmingeneratorGeneratorBundle::base_admin_assetic_less.html.twig

Next install assets in your web directory and start the admin generator setup:

php app/console assets:install web --symlink
php app/console admin:setup
 
Edit config.yml and configure the section admingenerator_generator like that:
admingenerator_generator:
    base_admin_template: AdmingeneratorGeneratorBundle::base_admin_assetic_less.html.twig
    use_propel: false
    use_doctrine_orm: true
    use_doctrine_odm: false
 
In section knp_menu :
knp_menu:
    twig: true
 
In JMS security :
jms_security_extra:
    expressions: true
 
php app/console admin:generate-admin

Leave a Reply