» Symfony 1.4 admin generator reference card «

Command Line

Options in this order: <APP> <MODULE> <OBJECT>

$ symfony doctrine:generate-admin backend post Post
$ symfony propel:generate-admin backend comment Comment

Generated code (can be overridden per module)

accessible in cache/backend/<ENV>/modules/<MODULE>

Actions

create -> edit
delete
edit
index -> list
list
save -> edit

Methods

public handleErrorEdit()
protected save<OBJECT>()
protected delete<OBJECT>()
protected update<OBJECT>FromRequest()
protected get<OBJECT>OrCreate()
protected processFilters()
protected processSort()
protected addFiltersCriteria()
protected addSortCriteria()

Templates

_edit_actions.php
_edit_footer.php
_edit_header.php
_filters.php
_list_actions.php
_list_footer.php
_list_header.php
_list_td_actions.php
_list_td_stacked.php
_list_td_tabular.php
_list_th_tabular.php
_list_th_stacked.php
editSuccess.php
listSuccess.php

generator.yml

generator:
  class:              sfPropelAdminGenerator
  param:
    model_class:            Post
    moduleName:             null
    actions_base_class:     sfActions
    singular:               post
    plural:                 post_list
    i18n_catalogue:         messages
    theme:                  default
    css:                    custom.css
    credentials:            []
    non_verbose_templates:  null
    route_prefix:           ''

    fields:
      author_id:        { label: Post author }
    
    list:
      title:            symfony blog posts
      display:          [title, author_id, category_id, published_on]
      fields:
        published_on:
          type: Date
          label: Published
          date_format:  'dd/MM/yy'
          is_real: true
      
      layout:           stacked
      params: |
        %%is_published%%<strong>%%=title%%</strong><br />
        <em>by %%author%% in %%category%% 
        (%%published_on%%)</em><p>%%content_summary%%</p>
      max_per_page:   2
      
    edit:   
      title:            Editing post "%%title%%"
      display:
        "Post":         [title, category_id, content]
        "Workflow":     [author_id, is_published, created_on]
      fields:
        category_id:    { params: disabled=true }
        content:
          params:       rich=true tinymce_options=height:150
        author_id:
          params:       size=5 include_custom=Choose an author
        is_published:   { credentials: [[admin, superdamin]] }
        created_on:     { type: Date, date_format: 'dd/MM' }

Display (ordering and grouping)

list view

The equal sign (=) selects the field holding the hyperlink to the edit view
    list:
      ## tabular layout
      display: [=title, author_id, created_at]
      
      ## stacked layout
      layout:  stacked
      display: [title, author_id, created_at] 
      params: |
        <strong>%%=title%%</strong>
        by %%author%% (issued on %%created_at%%)
Stacked layout uses display setting for the column headers (and sorting)

edit view

    edit:
      ## ungrouped 
      display:    [title, author_id, created_at]
      
      ## grouped
      display:
        "NONE":   [id]
        "Group1": [title, body]
        "Group2": [created_at]
Groups with label "NONE" have no label

Additional list settings

Filters

  filters:
    - title         ## text filter, accepts * as wildcard
    - author        ## foreign_key filter, displays select
    - created_at    ## date filter from... to...
    - is_admin      ## boolean filter, yes/no/yes or no

Pagination

  max_per_page: 10  ## maximum number of records per page

Sorting

  sort: created_at  ## sort column (ascending order by default)
  sort: [created_at, desc]  ## desc sort order

Interactions

Default actions

list:
  object_actions:
    _edit:    -
    _delete:  -          
  actions:
    _create:  -
edit:
  actions:        
    _list:         -
    _save:         -
    _save_and_add: -
    _delete:       -

Parameters

  actions:
    my_action:
      label:        Add a comment
      action:      addComment
      icon:        backend/addcomment.png
      only_for:    edit        ## Restrict to edit or create
      params:      class=foobar confirm=Are you sure?
      credentials: [[admin, superuser], owner]

Presentation

generator:
  class:          sfPropelAdminGenerator
  param:
    model_class:  Post
    theme:        mytheme              ## custom theme      
    css:          custom.css           ## replaces default css

Fields

Parameters

fields:
  my_field:
    label:        ## Field label/header
    help:        ## Tooltip, displays when requested
    type:        ## for edit view only, see below
    credentials: ## Classic AND/OR credentials array
    params:      ## html options, depending on the tag

Cascade

First declaration covers the whole module
can be specialized for each view
fields:
  author:   { label: Author }
list:
  fields:
    author: { help: This is the author of the comment } 
edit:
  fields:
    author: { label: Author of the comment }

Input types

fields:
  my_field:
    type:
      plain          ## No input
      input_tag      ## Default for text, numeric
      textarea_tag   ## Default for longvarchar
      input_date_tag ## Default for date and timestamp
      select_tag     ## Default for foreign keys
                     ## And for booleans
      checkbox_tag
      radiobutton_tag
      admin_input_upload_tag

Usual params

fields:
  my_field:
    params:
      disabled: true             
      date_format: 'MM/dd/yy' ## For dates but "type" must be "Date"
      include_blank: true     ## For select tags
      include_custom: Choose from the list
      size: 45x5              ## For textareas
      rich: true
      tinymce_options: height:150

Special fields

Custom fields

Fields not defined in the schema.xml but for which a custom getter and/or setter were defined in the model.
modules/post/config/generator.yml
list:
  display:        [nb_comments]
  fields:
    nb_comments:  { label: Number of comments }

apps/lib/model/Post.php
public function getNbComments()
{
  return count($this->getComments());
}

Partial fields

Fields declared with a _ prefix in the display: key refer to a partial in the module's template/ dir.
Use the name without prefix under the fields: key.
modules/comment/config/generator.yml
list:
  display:        [_post_link]
  fields:
    post_link:    { label: Related Post, is_real: false }

modules/comment/templates/_post_link.php
<php echo link_to(
  $comment->getPost()->getTitle(),
  'post/edit?id='.$comment->getPostId()
) ?>
Partials gain automatic access to the current object $<object>.