In this article we assume that you are familiar with The YAML Format and Configuration File Principles.
The admin generator of symfony allows the creation of a backend interface for your model classes. It works whether you use Propel or Doctrine as your ORM.
Admin generator modules are created by the propel:generate-admin or doctrine:generate-admin tasks:
php symfony doctrine:generate-admin backend Project --module=project php symfony propel:generate-admin backend Project --module=project
The above command creates a project admin generator module for the Project model class. And the configuration of such a module can be done in the apps/backend/modules/project/config/generator.yml file.
generator: class: <sfDoctrineGenerator | sfPropelGenerator> param: model_class: model_class_name theme: theme_name non_verbose_templates: <true | false> with_show: <true | false> singular: ~ plural: ~ with_doctrine_route: <true | false> route_prefix: route_prefix_name actions_base_class: class_name css: <css_filename | false> config: actions: action_name: label: action_label action: action_name credentials: action_credentials params: html_attribute: value absolute: <true | false> query_string: query_string_value anchor: anchor_value confirm: confirmation_message popup: <true | false> post: <true | false> method: <POST | DELETE | PUT> fields: field_name: label: field_label help: help_text attributes: { attribute1: value1, attribute2: value2, ... } credentials: field_credentials renderer: renderer_name renderer_arguments: [argument1, argument2, ...] type: type_of_column date_format: format_string is_link: <true | false> is_real: <true | false> is_partial: <true | false> is_component: <true | false> list: title: view_title display: [=fieldname1, fieldname2, ...] hide: [fieldname1, fieldname2, ...] layout: <tabular | stacked> params: params_string sort: [fieldname, <asc | desc>] max_per_page: <items_per_page | false> pager_class: class_name fields: field_list batch_actions: action_list object_actions: action_list actions: action_list table_method: method_name peer_method: method_name table_count_method: method_name peer_count_method: method_name filter: display: [fieldname1, fieldname2, ...] class: <class_name | false> fields: field_list form: display: [fieldname1, fieldname2, ...] class: class_name fields: field_list actions: action_list edit: display: [fieldname1, fieldname2, ...] title: view_title fields: field_list actions: action_list new: display: [fieldname1, fieldname2, ...] title: view_title fields: field_list actions: action_list
The generator.yml file must start with an generator key under which the whole configuration is done.
Specifies generator class name. Default: sfDoctrineGenerator (for Doctrine), sfPropelGenerator (for Propel)
Specifies an array of configuration options for the generated module.
Defines the model class bound to generated module.
Defines the default theme to use. Default: admin
It seems, that this option do not have any effect whether it is set to true or false; Possible values: <true | false> Default: true
Defines whether the generated action class implements a show action. In the standard Symfony distribution this option is not implemented. The with_show option is implemented only by the third party admin generator themes (eg. <a href=«http://www.symfony-project.org/plugins/ahAdminGeneratorThemesPlugin»>ahAdminGeneratorThemesPlugin</a>). Possible values: <true | false> Default: false
<p class=«feedback»><a href=«http://www.symfonyreference.com/update/singular/240»>You are welcome to provide description here</a></p>
</dl> </dd> </dl>
<p class=«feedback»><a href=«http://www.symfonyreference.com/update/plural/241»>You are welcome to provide description here</a></p>
</dl> </dd> </dl>
<p class=«feedback»><a href=«http://www.symfonyreference.com/update/with-doctrine-route/243»>You are welcome to provide description here</a></p>
Possible values: <true | false> Default: true
</dl> </dd> </dl>
Defines a route name to use for links in generated templates. This route must be added to routing.yml file and must be of class sfDoctrineRouteCollection (for Doctrine orm) or sfPropelRouteCollection (for Propel orm).
Defines a name of a class which is extended by the generated action class. Default: sfActions
Specifies the stylesheet to use in the generated module. If you want to use the default admin generator style, do not define this option. To deactivate the default admin generator theme, set css option to false.
Specifies an array of options where the main generator configuration is done. The config entry is organized into seven sections which by default are defined as empty, as the admin generator defines sensible defaults for all possible options:
generator: param: config: actions: ~ fields: ~ list: ~ filter: ~ form: ~ edit: ~ new: ~
Some of the options below can take model object placeholders. A placeholder is a string which follows the pattern: NAME. The NAME string can be anything that can be converted to a valid object getter method (get suffixed by the camel-cased version of the NAME string). For instance, title will be replaced by the value of $article→getTitle(). Placeholder values are dynamically replaced at runtime according to the object associated with the current context. When a model has a foreign key to another model, Propel and Doctrine define a getter for the related object. As for any other getter, it can be used as a placeholder if you define a meaningful __toString() method that converts the object to a string. The admin generator configuration is based on a configuration cascade principle. The inheritance rules are the following:
Defines a default configuration for the actions found on the list and on the forms.
Defines the action name to execute without the execute prefix. The framework defines several built-in actions. They are all prefixed by an underscore (eg.: _edit, _new, _delete, etc.). Each action can be customized with the options described in this section. The same options can be used when defining an action in the list, edit, or new entries.
Defines the label to use for the action. Default: The action_name key
Defines the action name to execute without the execute prefix. Default: The action_name key
Defines credentials the user must have for the action to be displayed. The credentials are to be defined with the same rules as in the security.yml configuration file. The credential management in the admin generator only takes care of the display. However, even if the link or button does not appear, the actions must still be properly secured from illicit access.
Defines an array of HTML parameters which are added to the action link (<a>). You can also specify any of the options available for the link_to() helper.
Specifies a HTML attribute and its value which is added to the action link (<a attribute=«value»>Action</a>).
If set to true, the generator renders an absolute URL for the action link. Possible values: <true | false>
Specifies a query string to append (starting by ?) to the action URL.
Specifies an anchor to append (starting by #) to the action URL.
Displays a javascript confirmation alert when the action link is clicked.
If set to true, the action link opens a new browser window. Possible values: <true | false>
If set to true, the link submits a POST request instead of GET. Possible values: <true | false>
If set to POST, DELETE, or PUT, the action link submits a request with the given HTTP method instead of GET.
Defines the default configuration for each field. This configuration is defined for all pages and can be overridden on a page per page basis (list, filter, form, edit, and new). Based on the context, the admin generator is smart enough to know how to render fields. To customize the rendering, you can create a partial or a component. By convention, partials are prefixed with an underscore (_), and components by a tilde (~):
display: [_title, ~content]
In the above example, the title field will be rendered by the title partial, and the content field by the content component. The admin generator passes some parameters to partials and components. For the New and Edit page:
For the List page:
Specifies a field name. A field can be a real column name, or a virtual one. In both cases, a getter must be defined in the model class (get suffixed by the camel-cased field name).
Defines the label to use for the field. Default: The humanized column name
Defines the help text to display for the field.
Defines the HTML attributes to pass to the widget, eg.:
config: fields: slug: attributes: class: foo disabled: true
Defines credentials the user must have for the field to be displayed. The credentials are only enforced for the object list. The credential are to be defined with the same rules as in the security.yml configuration file, eg.:
config: fields: slug: credentials: [[admin, moderator]]
Defines a PHP callback to call to render the field. If defined, it overrides any other flag like the partial or component ones. The callback is called with two parameters: the value of the field and the array of arguments defined by the renderer_arguments option. Below is an example of how to render field text using rendertext function:
config: fields: name: renderer: rendertext
You can also use static methods in any class for a callback function:
config: fields: name: renderer: [MyClass, rendertext]
In previous example MyClass::rendertext method will be called to render field text.
Defines an array of arguments to pass to the renderer PHP callback when rendering the field. It is only used if the renderer option is defined. Default: array()
Defines the type of the column. By default, symfony uses the type defined in your model definition, but if you create a virtual column, you can override the default Text type by one of the valid types:
Defines the format to use when displaying dates. It can be any format recognized by the sfDateFormat class. This option is not used when the field type is Date. The following tokens can be used for the format:
For more information visit: <a href=«http://trac.symfony-project.org/wiki/formatDateHowTo»>http://trac.symfony-project.org/wiki/formatDateHowTo</a> Default: f
Specifies whether or not to convert the field value to a link that goes to the Edit page of the current object. This option is equivalent to the equal sign ( in the display option.
Possible values: <true | false>
Default: false
Specifies whether or not to display the sort link in the list view header. If you customize the list view to include columns that displays data from a foreign table or from virtual columns, the generator will not automatically create sort links for them. You must set is_true option to true and modify your action and model classes to include sorting logic for those columns. You can find the <a href=«http://stereointeractive.com/blog/2011/01/08/symfony-1-4-admin-generator-sort-on-custom-column/»>full story here</a>. Possible values: <true | false> Default: true (for root table colums), false (for virtual or foreign columns)
If set to true, Symfony tries to include the partial, which name equals to field_name and which must display fields value. Possible values: <true | false> Default: false
If set to true, Symfony tries to include the component, which name equals to field_name and which must display fields value. If specified both is_component and is_partial, is_component takes precedence. Possible values: <true | false> Default: false
Defines a configuration for the list.
Defines the title of the list page. Default: The humanized model class name suffixed with «List»
Defines an array of ordered columns to display in the list.
An equal sign ( before a column is a convention to convert the string to a link that goes to the Edit page of the current object:
config: list: display: [=name, slug]
Default: All model columns, in the order of their definition in the schema file
Defines the columns to hide from the list. It is opposite to the display[/i option. Instead of specifying the columns to be displayed with the [i]display option, it is sometimes faster to hide some columns:
config: list: hide: [created_at, updated_at]
If both the display and the hide options are provided, the hide option is ignored.
Defines what layout to use to display the list. With the tabular layout, each column value is in its own table column. With the stacked layout, each object is represented by a single string, which is defined by the params option (see below). The display option is still needed when using the stacked layout as it defines the columns that will be sortable by the user. Possible values: <tabular | stacked> Default: tabular
This option is used to define the HTML string pattern to use when using a stacked layout. This string can contain model object placeholders:
config: list: params: | %%=title%% written by %%author%% and published on %%published_at%%.
An equal sign ( before a column is a convention to convert the string to a link that goes to the Edit page of the current object.
Defines the default sort column. It is an array composed of two components: the column name and the sort order: asc or desc:
config: list: sort: [published_at, desc]
Defines the maximum number of objects to display on one page. To completely remove the pagination feature, set the max_per_page to false. Default: 20
Defines the pager class to use when displaying the list. Default: sfPropelPager (for Propel), sfDoctrinePager (for Doctrine)
Defines a configuration for the fields available in List page. You can configure every field using the same options as defined in «Default configuration for the fields» section.
Defines the list of actions that can be executed for a selection of objects in the list. If you don't define an action parameter, the admin generator will look for a method named after the camel-cased name prefixed by executeBatch. The executed method receives the primary keys of the selected objects via the ids request parameter. The batch actions feature can be disabled by setting the option to an empty array: {} Default: { _delete: ~ }
Defines the list of actions that can be executed on each object of the list, eg.:
object_actions: moveUp: { label: "move up", action: "moveUp" } moveDown: { label: "move down" } _edit: ~ _delete: ~
If you don't define an action parameter, the admin generator will look for a method named after the camel-cased name prefixed by executeList. The object actions feature can be disabled by setting the option to an empty array: {} Default: { _edit: ~, _delete: ~ }
Defines actions that take no object, like the creation of a new object. If you don't define an action parameter, the admin generator will look for a method named after the camel-cased name prefixed by executeList. The actions feature can be disabled by setting the option to an empty array: {}. Default: { _new: ~ }
Defines the method to call to retrieve the objects to display in the list. This method must be created in the model table class and takes Doctrine_Query object as a parameter, which you can modify further, eg.:
class ObjectTable extends Doctrine_Table { public function retrieveObjectList(Doctrine_Query $q) { $rootAlias = $q->getRootAlias(); $q->leftJoin($rootAlias . '.ObjectCategory c'); return $q; } }
This option only exists for <strong>Doctrine</strong>. For Propel, use the peer_method option. Default: doSelect
Defines the method to call to retrieve the objects to display in the list. This option only exists for <strong>Propel</strong>. For Doctrine, use the table_method option. Default: doSelect
Defines the method to call to compute the number of objects for the current filter. This option only exists for <strong>Doctrine</strong>. For Propel, use the peer_count_method option. Default: doCount
Defines the method to call to compute the number of objects for the current filter. This option only exists for <strong>Propel</strong>. For Doctrine, use the table_count_method option. Default: doCount
Defines the configuration for the filtering form displayed on the List page.
Defines the ordered list of fields to display in the filter form. Note that as filter fields are always optional, there is no need to override the filter form class to configure the fields to be displayed. Default: All fields defined in the filter form class, in the order of their definition
Defines the form class to use for the filter form. To completely remove the filtering feature, set the class to false. Default: The model class name suffixed by FormFilter
Defines a configuration for the fields available in filter form. You can configure every field using the same options as defined in «Default configuration for the fields» section.
Defines configuration for the New and Edit pages.The form section only exists as a fallback for the edit and new sections (edit and new sections inherits all options from the form section).
Defines the ordered list of fields to display in Edit and New pages. This option can also be used to arrange fields into groups:
config: form: display: NONE: [id] Content: [title, body, author] Admin: [is_published, expires_at]
The above configuration defines two groups (NONE, Content and Admin), each containing a subset of the form fields. Groups with label «NONE» have no label. Default: All fields defined in the form class, in the order of their definition
Specifies the form class to use in Edit and New pages.
Defines a default configuration for the fields found on the Edit and New forms. You can configure every field using the same options as defined in «Default configuration for the fields» section.
Defines a default configuration for the actions found on the Edit and New pages. You can configure every action using the same options as defined in «Default configuration for the actions» section. Default: { _delete: ~, _list: ~, _save: ~, _save_and_add: ~ }
Defines a specific configuration for the Edit page.
Defines the ordered list of fields to display in the Edit page. This option can also be used to arrange fields into groups (example is provided in the «Default forms configuration» section). If not defined, this option inherits value from the display option in the form section. Default: All fields defined in the form class, in the order of their definition
Defines the title heading of the Edit page. It can contain model object placeholders. Default: «Edit » suffixed by the humanized model class name
Defines a configuration for the fields available in Edit form. You can configure every field using the same options as defined in «Default configuration for the fields» section.
Defines actions available in Edit page. You can configure every action using the same options as defined in «Default configuration for the actions» section. Default: { _delete: ~, _list: ~, _save: ~ }
Defines a specific configuration for the New page.
Defines the ordered list of fields to display in the New page. This option can also be used to arrange fields into groups (example is provided in the «Default forms configuration» section). If not defined, this option inherits value from the display option in the form section. Default: All fields defined in the form class, in the order of their definition
Defines the title of the New page. It can contain model object placeholders. Default: «New » suffixed by the humanized model class name
Defines a configuration for the fields available in New form. You can configure every field using the same options as defined in «Default configuration for the fields» section.
Defines actions available in New page. You can configure every action using the same options as defined in «Default configuration for the actions» section. Default: { _delete: ~, _list: ~, _save: ~, _save_and_add: ~ }
</div>
</div></body><link id=«apn-null-stylesheet» rel=«stylesheet» href=«chrome-extension:aaaapkhcbchjhhhbhljkcpmldmflnccm/config/skin/css/containers.css»><iframe id=«apn-null-toolbar» src=«./Symfony YAML Configuration Reference generator.yml file_files/toolbar.htm» class=«apn-toolbar SkipThisFixedPosition apn-v5-toolbar» style=«top: 0px;»></iframe><style id=«apn-body-style»>html { padding-top: 34px ! important; border-top: 1px solid transparent; }</style></html>