Symfony 3.2.7 和奏鸣曲媒体包安装

Posted

技术标签:

【中文标题】Symfony 3.2.7 和奏鸣曲媒体包安装【英文标题】:Symfony 3.2.7 and sonata media bundle installation 【发布时间】:2017-09-17 05:38:20 【问题描述】:

我正在尝试在 symfony 3.2.7/php7/doctrine 环境中安装奏鸣曲媒体包。

我正在关注这个文档:https://sonata-project.org/bundles/media/3-x/doc/reference/installation.html

但是当我使用此命令行生成数据库时出现错误:php bin/console dictionary:schema:update --force

错误信息:

[Doctrine\DBAL\DBALException]
  Unknown column type "json" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addT
  ype(). You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during da
  tabase introspection then you might have forgot to register all database types for a Doctrine Type. Use AbstractPlatform#regis
  terDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseTypes(). If the type name is empty you migh
  t have a problem with the cache or forgot some mapping information.

另外,当我输入这个命令行时:php bin/console dictionary:schema:validate

我收到以下消息:

[Mapping]  FAIL - The entity-class 'Sonata\MediaBundle\Entity\BaseMedia' mapping is invalid:
* The field 'Sonata\MediaBundle\Entity\BaseMedia#providerMetadata' uses a non-existant type 'json'.

[Mapping]  FAIL - The entity-class 'Application\Sonata\MediaBundle\Entity\Media' mapping is invalid:
* The field 'Application\Sonata\MediaBundle\Entity\Media#providerMetadata' uses a non-existant type 'json'.

这是我的 composer.json:

"require": 
"php": ">=5.5.9",
"symfony/symfony": "3.2.*",
"doctrine/orm": "^2.5",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/doctrine-cache-bundle": "^1.2",
"symfony/swiftmailer-bundle": "^2.3.10",
"symfony/monolog-bundle": "^3.0.2",
"symfony/polyfill-apcu": "^1.0",
"sensio/distribution-bundle": "^5.0",
"sensio/framework-extra-bundle": "^3.0.2",
"incenteev/composer-parameter-handler": "^2.0",
"symfony/intl": "^3",
"hautelook/alice-bundle": "^1.3",
"doctrine/doctrine-fixtures-bundle": "^2.3",
"friendsofsymfony/user-bundle": "~2.0@dev",
"jms/translation-bundle": "dev-master",
"jms/i18n-routing-bundle": "dev-master",
"sonata-project/admin-bundle": "^3.16",
"sonata-project/doctrine-orm-admin-bundle": "^3.1",
"sonata-project/media-bundle": "^3.5"
,

你知道我做错了什么吗?

这是我的 config.yml:

doctrine:
orm:
    entity_managers:
        default:
            mappings:
                ApplicationSonataMediaBundle: ~
                SonataMediaBundle: ~


dbal:
    types:
        json: Sonata\Doctrine\Types\JsonType

sonata_media:
# if you don't use default namespace configuration
#class:
#    media: MyVendor\MediaBundle\Entity\Media
#    gallery: MyVendor\MediaBundle\Entity\Gallery
#    gallery_has_media: MyVendor\MediaBundle\Entity\GalleryHasMedia
db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr it is mandatory to choose one here
default_context: default # you need to set a context
contexts:
    default:  # the default context is mandatory
        providers:
            - sonata.media.provider.dailymotion
            - sonata.media.provider.youtube
            - sonata.media.provider.image
            - sonata.media.provider.file
            - sonata.media.provider.vimeo

        formats:
            small:  width: 100 , quality: 70
            big:    width: 500 , quality: 70

cdn:
    server:
        path: /uploads/media # http://media.sonata-project.org/

filesystem:
    local:
        directory:  "%kernel.root_dir%/../web/uploads/media"
        create:     false

【问题讨论】:

【参考方案1】:

您的 config.yml 标识错误

这应该是正确的,根据https://sonata-project.org/bundles/media/3-x/doc/reference/installation.html

doctrine:
    orm:
        entity_managers:
            default:
                mappings:
                    ApplicationSonataMediaBundle: ~
                    SonataMediaBundle: ~


    dbal:
        types:
            json: Sonata\Doctrine\Types\JsonType

sonata_media:
    # if you don't use default namespace configuration
    #class:
    #    media: MyVendor\MediaBundle\Entity\Media
    #    gallery: MyVendor\MediaBundle\Entity\Gallery
    #    gallery_has_media: MyVendor\MediaBundle\Entity\GalleryHasMedia
    db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr it is mandatory to choose one here
    default_context: default # you need to set a context
    contexts:
        default:  # the default context is mandatory
            providers:
                - sonata.media.provider.dailymotion
                - sonata.media.provider.youtube
                - sonata.media.provider.image
                - sonata.media.provider.file
                - sonata.media.provider.vimeo

            formats:
                small:  width: 100 , quality: 70
                big:    width: 500 , quality: 70

    cdn:
        server:
            path: /uploads/media # http://media.sonata-project.org/

    filesystem:
        local:
            directory:  "%kernel.root_dir%/../web/uploads/media"
            create:     false

【讨论】:

可惜不是这样,只是我复制粘贴的标识有问题

以上是关于Symfony 3.2.7 和奏鸣曲媒体包安装的主要内容,如果未能解决你的问题,请参考以下文章

Symfony 2 Sonata 媒体包:在没有奏鸣曲管理员的情况下保存媒体文件图像

如何在 symfony 中覆盖奏鸣曲媒体包的默认上传路径?

Symfony:奏鸣曲媒体文件预览

奏鸣曲媒体包修改 MediaType

奏鸣曲媒体包中的错误

Symfony 4 为奏鸣曲管理包安装 sensio/generator-bundle 时出错