Symfony admin generator

Admin Generator is an awesome tool available via the symfony framework for doctrine (and propel). Based on the model it will automatically generate tedious forms for you to admin the various objects associated with your model.

php symfony doctrine:generate-admin app_name model_name --module=module_name
php symfony doctrine:build-filters
php symfony doctrine:build-forms
php symfony cc

Ok you should now be able to see your admin interface @ http://yourdomain.com/<app_name>_dev.php/<module_name>. Pretty cool huh? You should now have access to forms that allow you to manipulate data. So in a few easy steps you just saved yourself days of work.

Setting default route

vi apps/<app_name>/config/routing.yml

Before

homepage:
  url:   /
  param: { module: default, action: index }

After

homepage:
 url:   /
 param: { module: module_name, action: index }

Configure form attributes

You can now customize form attributes by editing the following file:

vi apps/app_name/modules/module_name/config/generator.yml

As you can see in the file there are a number of attributes you can configure, and we will go over some of the attributes we need to configure in order to custom tailor your admin app.

First lets change the page title, this attribute will change the default ‘<model> List’ to something more to your liking, maybe ‘<model> Management’. To do this simply add the following line under the ‘list:’ category:

Before

...
  config:
    ...
      list: ~

After

...
  config:
    ...
      list:
        title: object Management

Yep, it’s that simple. Go ahead and refresh the page. If you don’t see the page you may need to clear cache:

php symfony cc

Now we’ll edit the titles of the action views; editing or creating a new <object>

Before

...
  config:
    ...
      edit: ~
      new: ~

After

...
  config:
    ...
      edit:
        Editing <object> "%%<name_field>%%"
      new:
        New <object>

Refresh the page and click on new and edit to see the changes (if you don’t, be sure to clear cache). You can also configure how the rows from your <object> table are displayed. If your table is wide you may want to remove a few elements so you can keep the rows from wrapping, you can do that by editing the list sub category:

Before

...
  ...
    config:
      list:
        ...

After

...
  ...
    config:
      list:
        ...
        display: [=<name_column>, <another_column>, <yet_another_column>]

Now refresh your page. You should see your <name_column> first (notice it’s rendered as an html link, this is what the = modifier does), <another_column> and <yet_another_column>. Cool!

Remove Batch Actions

Batch actions refer to the ability to check multiple checkboxes then select an option from the drop down menu. If you don’t need these you can remove them:

Before

...
  ...
    ...
      config:
        list:
          ...

After

...
  ...
    ...
      config:
        list:
           batch_actions: {}

Remove object actions

If you want to remove object level actions (delete, edit by default) from each objects row:

Before

...
  ...
    config:
      list:
        ...

After

...
  ...
    config:
      list:
        object_actions: {}

Remove unwanted elements

You may notice some form elements that you do not want to display on the form. For example it’s quite possible you have a created_at and updated_at column that belongs to the object model you are working with. These object attributes should not be editable by any app users as they should be controlled by the database engine from which the model files were created. So lets go ahead and remove them so they can’t be directly edited.

vi lib/form/doctrine/<object_name>Form.class.php

Before

public function configure() {
}

After

public function configure() {
    unset($this['created_at'], $this['updated_at']);
}

Boolean Datatypes

If you have any boolean (tinyint(1)) data types in your schema you may want to refer to this post to change them so your forms will display a checkbox and not an input field.

Work in progress…