Development

Changeset 1342

You must first sign up to be able to contribute.

Changeset 1342

Show
Ignore:
Timestamp:
05/11/06 15:21:52 (3 years ago)
Author:
francois
Message:

documented partial support for custom filters and default sorting option for admin generator

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/doc/book/content/generator.txt

    r1193 r1342  
    343343The resulting filter will allow text-based search on an author name (where the `*` character can be used as a joker), and the selection of the comments related to a given article by a choice in a selection list. As for regular `object_select_tag()`, the options displayed in a select are the ones returned by the `->toString()` method of the related class (or the primary key if such a method doesn't exist). 
    344344 
     345Just like you use partial fields in lists, you can also use partial filters to create a filter that symfony doesn't handle on its own. For instance, imagine a `state` field that may only contain 2 values (`open` and `closed`), but for some reason you store those values directly in the field instead of using a table relation. A simple filter on this field (of string type) would be a text-based search, but what you want is probably a select with a list of values. That's quite easy to achieve with a partial filter: 
     346 
     347        list: 
     348          filters:        [date, _state] 
     349 
     350Then, in `templates/_state.php`: 
     351 
     352    [php] 
     353    <?php echo select_tag('filters[state]', options_for_select(array( 
     354      '' => '', 
     355      'open' => 'open', 
     356      'closed' => 'closed', 
     357    ), isset($filters['state']) ? $filters['state'] : '')) ?> 
     358     
     359Notice that the partial has access to a `$filters` variable, whiwh is very useful to get the current value of the filter. 
     360 
    345361### Sort 
    346362 
     
    351367    [php] 
    352368    <?php echo link_to('Comment list by date', 'comment/list?sort=date&type=desc' ) ?> 
     369 
     370You can also define a default sort field for the `list` view directly in the `generator.yml`: 
     371 
     372        list: 
     373          sort:   date 
     374 
     375Or, if you want to specify the sort order: 
     376 
     377        list: 
     378          sort:   [date, desc] 
    353379 
    354380### Pagination