这个文档主要涉及list视图,在系统中你使用它来浏览对象。涉及到的配置主要是list页面自己和过滤器(你能够使用它来控制什么条件可见)。
7.1 基础配置
在list视图中,SonataAdmin的配置会影响这些。
1 2 3 4 5 6 7 8 9 10 11 12 |
sonata_admin: templates: list: SonataAdminBundle:CRUD:list.html.twig action: SonataAdminBundle:CRUD:action.html.twig select: SonataAdminBundle:CRUD:list__select.html.twig list_block: SonataAdminBundle:Block:block_admin_list.html.twig short_object_description: SonataAdminBundle:Helper:short-object-description.html.twig batch: SonataAdminBundle:CRUD:list__batch.html.twig inner_list_row: SonataAdminBundle:CRUD:list_inner_row.html.twig base_list_field: SonataAdminBundle:CRUD:base_list_field.html.twig pager_links: SonataAdminBundle:Pager:links.html.twig pager_results: SonataAdminBundle:Pager:results.html.twig |
7.2 自定义字段显示在列表页(list page)
你可以通过configureListFields方法来显示并配置自定义字段。这里有一个Sonata E-Commerce Product Admin的例子:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
<?php // ... public function configureListFields(ListMapper $listMapper) { $listMapper // addIdentifier allows to specify that this column // will provide a link to the entity // (edit or show route, depends on your access rights) ->addIdentifier('name') // you may specify the field type directly as the // second argument instead of in the options ->add('isVariation', 'boolean') // if null, the type will be guessed ->add('enabled', null, array( 'editable' => true )) // we can add options to the field depending on the type ->add('price', 'currency', array( 'currency' => $this->currencyDetector->getCurrency()->getLabel() )) // here we specify which method is used to render the label ->add('productCategories', null, array( 'associated_tostring' => 'getCategory' )) ->add('productCollections', null, array( 'associated_tostring' => 'getCollection' )) // you may also use dotted-notation to access // specific properties of a relation to the entity ->add('image.name') // You may also specify the actions you want to be displayed in the list ->add('_action', 'actions', array( 'actions' => array( 'show' => array(), 'edit' => array(), 'delete' => array(), ) )) ; } |
7.2.1 选项
提示:(m)强制(o)可选
type (m) : 定义字段类型 – 这是一个强制性的字段,如果不指定的话,他会尝试猜测字段类型。
template (o) : 使用这个模板来渲染字段。
label (o) : 更改字段title的名称
link_parameters (o) : 当调用Admin::generateUrl时,添加link参数到关联的admin类
code (o)
未完待续中。。。。。。