php - how to call my second entity with property? -
i've problem sonataadminbundle
.
i have file admin.yml:
sonata.admin.produit: class: kayser\platformbundle\admin\productionadmin tags: - { name: sonata.admin, manager_type: orm, group: "produits", label: "les pains & viennoiseries" } arguments: - ~ - kayser\platformbundle\entity\product - ~ calls: - [ settranslationdomain, [kayserplatformbundle]] sonata.admin.produit: class: kayser\platformbundle\admin\productionadmin tags: - { name: sonata.admin, manager_type: orm, group: "produits", label: "les pains & viennoiseries" } arguments: - ~ - kayser\platformbundle\entity\productimage - ~ calls: - [ settranslationdomain, [kayserplatformbundle]]`
and productionadmin.php:
class productionadmin extends admin { // fields shown on create/edit forms protected function configureformfields(formmapper $formmapper) { $formmapper ->add('description', 'text', array('label' => 'description')) ->add('name') ->add('url', 'entity', array( 'class' => 'kayserplatformbundle:productimage', 'property' => 'name', 'multiple' => true)) ; } // fields shown on filter forms protected function configuredatagridfilters(datagridmapper $datagridmapper) { $datagridmapper ->add('name') ->add('description') ->add('url', 'entity', array( 'class' => 'kayserplatformbundle:productimage', 'property' => 'name', 'multiple' => true)) ; } // fields shown on lists protected function configurelistfields(listmapper $listmapper) { $listmapper ->addidentifier('name') ->add('description') ->add('url', 'entity', array( 'class' => 'kayserplatformbundle:productimage', 'property' => 'name', 'multiple' => true)) ; } }
and 2 entity product.php
, productimage.php
(they have no problem).
so how call second entity property ? :)
to property of entity in admin file, use this:
->add( 'productimage', 'entity', array( 'label' => 'url', 'class' => 'path/to/productimage', 'property' => 'url', ) )
this docs give example:
<?php namespace acme\demobundle\admin; use sonata\adminbundle\admin\admin; use sonata\adminbundle\datagrid\listmapper; use sonata\adminbundle\datagrid\datagridmapper; use sonata\adminbundle\form\formmapper; class postadmin extends admin { // fields shown on create/edit forms protected function configureformfields(formmapper $formmapper) { $formmapper ->add('title', 'text', array('label' => 'post title')) ->add('author', 'entity', array('class' => 'acme\demobundle\entity\user')) ->add('body') //if no type specified, sonataadminbundle tries guess ; }
more info in docs
Comments
Post a Comment