2

Sonata Admin Gallery 機能を自分のNews Entity. これが私のコードです

News.yml

....

manyToOne:
    gallery:
        targetEntity: Application\Sonata\MediaBundle\Entity\Gallery
        inversedBy: news_gallery
        cascade: ["persist"] 
        nullable: true

Gallery.orm.xml

....

<one-to-many field="news_gallery" 
                 target-entity="Wenweipo\NewsBundle\Entity\News"
                 mapped-by="gallery" /> 

NewsAdmin.php

protected function configureFormFields(FormMapper $formMapper) {

    $formMapper
        ->add('gallery', 'sonata_type_collection', array(
                'cascade_validation' => true,
                    ), array(
                'edit' => 'inline',
                'inline' => 'table',
                'sortable' => 'position',
                'link_parameters' => array(
                    'context' => 'images_news',
                ),
                        'admin_code'=>'sonata.media.admin.gallery_has_media'
            ))

}

管理コードを実行すると、このエラーが表示されます。

INVALID MODE : s543e4bf7bc21f_gallery - type : sonata_type_collection - mapping : 2 

私は何を間違っていますか?

4

1 に答える 1

1

NewsHasMedaのように保持される独自の関係を作成してみてくださいGalleryHasMedia

News.orm.yml

........
oneToMany:
    news_has_media:
        targetEntity: Wenweipo\NewsBundle\Entity\NewsHasMedia
        mappedBy: news 
        cascade: ["persist","remove"]
        orphanRemoval: true

という名前の別のエンティティを作成します。次にNewsHasMedia.ymlymlファイルに次のようなコードを追加します

NewsHasMedia.orm.yml

........
fields:

    enabled:
        type: boolean
        nullable: true
    position:
        type: integer
        nullable: true
    createdAt:
        type: datetime
        column: created_at
        nullable: true
    updatedAt:
        type: datetime
        column: updated_at
        nullable: true


manyToOne:

    media:
        targetEntity: Application\Sonata\MediaBundle\Entity\Media
        cascade: ["persist"]
        joinColumn:
            name: media_id   
            referencedColumnName: id
            #nullable: true 

    news:
        targetEntity: News
        inversedBy:  news_has_media
        cascade: ["persist"]
        joinColumn:
            name: news_id   
            referencedColumnName: id

次に、このエンティティを生成します。次に、管理ファイルにこれを追加します

NewsAdmin.php

->add('news_has_media', 'sonata_type_collection', array(

   'cascade_validation' => true), array(

            'edit' => 'inline',
            'inline' => 'table',
            'sortable' => 'position',
            'link_parameters' => array(
                'context' => 'images_news',
            ),

        ))

admin_codeこれで問題が解決することを願っています。

于 2014-10-20T17:41:44.460 に答える