doujia4041 2015-04-22 15:03
浏览 6

如何使用属性调用我的第二个实体?

I've actually a problem with SonataAdminBundle.

I have a 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 my productionAdmin.php:

class ProductionAdmin extends Admin
{
// Fields to be 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 to be 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 to be 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 and ProductImage.php (they have no problem).

So how to call my second entity with property ? :)

  • 写回答

1条回答 默认 最新

  • duanping1632 2015-04-22 15:52
    关注

    To get a property of another entity in your admin file, I use something like this:

    ->add(
        'productImage',
        'entity',
         array(
           'label' => 'Url',
           'class' => 'path/to/ProductImage',
           'property' => 'url',  
         )
      )
    

    This is what the docs give for 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 to be 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 is specified, SonataAdminBundle tries to guess it
           ;
       }
    

    More info in the docs

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法