简体   繁体   English

在sonata_type_collection中指定哪个管理员代码?

[英]Which admin_code to specify in sonata_type_collection?

In a Sonata project, I have a Page entity and a Media entity. 在Sonata项目中,我有一个Page实体和一个Media实体。 My Page entity contains an images property that contains an ArrayCollection of Media entities. 我的页面实体包含一个images属性,该属性包含一个Media实体的ArrayCollection。 In my Page entity, I the following working code: 在我的Page实体中,我下面的工作代码:

            ->add('galleries', 'sonata_type_collection', array(
                'label' => "Galleries",
                //'cascade_validation' => true,
                'required' => false,
            ), array(
                'edit' => 'inline',
                'inline' => 'table',
            ))

... which gives me a nice inline form on my Page editing screen, allowing me to create and associate galleries inline. ...这在页面编辑屏幕上为我提供了一个不错的内联表单,使我可以内联创建和关联画廊。

But when I try this: 但是当我尝试这个:

            ->add('images', 'sonata_type_collection', array(
                'label' => "Standalone Images",
                //'cascade_validation' => true,
                'required' => false,
            ), array(
                'edit' => 'inline',
                'inline' => 'table',
            ))

... I find that I get a blank checkbox, with no form. ...我发现我得到一个空白的复选框,没有表格。 (The page's images field contains an ArrayCollection of Media objects from the Sonata Media Bundle.) (页面的images字段包含Sonata Media Bundle中的Media对象的ArrayCollection。)

I assume I need to use the admin_code option to specify an admin value. 我假设我需要使用admin_code选项来指定一个admin值。 What string should I put in that option? 我应该在该选项中输入什么字符串?

=== ===

Edit #1: 编辑#1:

By changing this: 通过更改此:

                ->add('images', 'sonata_type_collection', array(
                    'label' => "Standalone Images",
                    'required' => false,
                ), array(
                    'edit' => 'inline',
                    'inline' => 'table',
                ))

... to this: ...对此:

                ->add('images', 'sonata_type_collection', array(
                    'label' => "Standalone Images",
                    'required' => false,
                ), array())

... I am able to get a modal box to show up for creating new Media entities. ...我可以看到一个模态框,用于创建新的Media实体。

However, I then find that the new media entities do no show up on my Page editing screen. 但是,然后我发现新的媒体实体没有显示在我的页面编辑屏幕上。 So this only partially fixes the problem. 因此,这只能部分解决问题。

=== ===

Edit #2: 编辑#2:

A bit of logging reveals that my Page entity's getImages() method is getting called, but that same entity's setImages() and addImage() methods are not getting called. 一些记录表明,我的Page实体的getImages()方法被调用,但是同一实体的setImages()和addImage()方法没有被调用。 I am not sure how to force the application to call these methods, nor how to make sure that the correct Media entities get fed to those methods. 我不确定如何强制应用程序调用这些方法,也不确定如何确保将正确的Media实体馈入这些方法。

=== ===

Edit #3: 编辑#3:

Here is the mapping in my Page.orm.xml file: 这是我的Page.orm.xml文件中的映射:

    <many-to-many field="images" target-entity="Application\Sonata\MediaBundle\Entity\Media">
        <cascade>
            <cascade-persist />
        </cascade>
        <join-table name="page_image">
            <join-columns>
                <join-column name="page_id" referenced-column-name="id" />
            </join-columns>
            <inverse-join-columns>
                <join-column name="image_id" referenced-column-name="id" unique="true" />
            </inverse-join-columns>
        </join-table>
    </many-to-many>

If you edit your collections inside another admin, you have to set the by_reference option to false. 如果您在另一个管理员内部编辑集合,则必须将by_reference选项设置为false。 Thats for calling the setter method on the embedded objects. 那就是在嵌入式对象上调用setter方法。 Especially on many to many relations its a common problem. 特别是在多对多关系上,这是一个普遍的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM