Sonata Media Bundle 安装错误

Posted

技术标签:

【中文标题】Sonata Media Bundle 安装错误【英文标题】:Sonata Media Bundle Installation error 【发布时间】:2018-01-16 01:15:54 【问题描述】:

正在尝试在 symfony 3.3.6 上安装奏鸣曲媒体包

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

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

错误信息:

[Doctrine\DBAL\DBALException] 请求的未知列类型“json”。 您使用的任何 Doctrine 类型都必须注册 \Doctrine\DBAL\Types\Type::addType()。你可以得到所有的列表 已知类型与 \Doctrine\DBAL\Types\Type::getTypesMap()。如果这 数据库自省期间发生错误,那么您可能已经忘记了 为 Doctrine Type 注册所有数据库类型。采用 AbstractPlatform#registerDoctrineType Mapping() 或有您的自定义 类型实现 Type#getMappedDatabaseTypes()。如果类型名称是 空你可能有缓存问题或忘记了一些映射 信息。

我的 config.yml 取自文档。我查看了所有此类文章,但在任何地方都找不到答案。为什么会出现这个错误?请帮忙,我开始失望了

【问题讨论】:

【参考方案1】:

您必须在您的学说配置中添加 json 类型:

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

在您的配置文件中,您有两次教义部分。 应用第一个:

doctrine:
    dbal:
        driver: pdo_mysql
        host: '%database_host%'
        port: '%database_port%'
        dbname: '%database_name%'
        user: '%database_user%'
        password: '%database_password%'
        charset: UTF8
        # if using pdo_sqlite as your database driver:
        #   1. add the path in parameters.yml
        #     e.g. database_path: '%kernel.project_dir%/var/data/data.sqlite'
        #   2. Uncomment database_path in parameters.yml.dist
        #   3. Uncomment next line:
        #path: '%database_path%'

    orm:
        auto_generate_proxy_classes: '%kernel.debug%'
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true

你没有在那里定义 JSON 类型。

【讨论】:

我有这个结构 你有两次学说部分。这是不可接受的。您必须合并此配置。第一个已应用,但那里没有 JSON 类型。 天啊!我有怀疑,但我是交响乐的新手,非常感谢! 现在,我正在尝试执行命令code php bin/console dictionary:schema:update 并且有错误 php bin/console 学说:schema:update --force 致命错误:未捕获的异常 'Symfony\Component\Config\Definition\Exception\InvalidConfigurationException' 带有消息 'Unrecognized options "naming_strategy, auto_mapping " 在 W:\domains\localhost\blog\vendor\symfony\symfony\src\Symfony\Component\Config\Definition\ArrayNode.php:317 中的 "doctrine.orm"' 下 【参考方案2】:
 imports:
    -  resource: parameters.yml 
    -  resource: security.yml 
    -  resource: services.yml 
    -  resource: "@AppBundle/Resources/config/admin.yml" 
    -  resource: sonata_classification.yml 
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
    locale: ru

framework:
    #esi: ~
    translator:  fallbacks: ['%locale%'] 
    secret: '%secret%'
    router:
        resource: '%kernel.project_dir%/app/config/routing.yml'
        strict_requirements: ~
    form: ~
    csrf_protection: ~
    validation:  enable_annotations: true 
    #serializer:  enable_annotations: true 
    templating:
        engines: ['twig']
    default_locale: '%locale%'
    trusted_hosts: ~
    session:
        # https://symfony.com/doc/current/reference/configuration/framework.html#handler-id
        handler_id: session.handler.native_file
        save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'
    fragments: ~
    http_method_override: true
    assets: ~
    php_errors:
        log: true

# Twig Configuration
twig:
    debug: '%kernel.debug%'
    strict_variables: '%kernel.debug%'

# Doctrine Configuration
doctrine:
    dbal:
        driver: pdo_mysql
        host: '%database_host%'
        port: '%database_port%'
        dbname: '%database_name%'
        user: '%database_user%'
        password: '%database_password%'
        charset: UTF8
        # if using pdo_sqlite as your database driver:
        #   1. add the path in parameters.yml
        #     e.g. database_path: '%kernel.project_dir%/var/data/data.sqlite'
        #   2. Uncomment database_path in parameters.yml.dist
        #   3. Uncomment next line:
        #path: '%database_path%'

    orm:
        auto_generate_proxy_classes: '%kernel.debug%'
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true

# Swiftmailer Configuration
swiftmailer:
    transport: '%mailer_transport%'
    host: '%mailer_host%'
    username: '%mailer_user%'
    password: '%mailer_password%'
    spool:  type: memory 

#Cache
doctrine_cache:
    providers:
        my_markdown_cache:
            type: file_system
            file_system:
                directory: /tmp/doctrine_cache

sonata_admin:
    title: My Blog Admin


sonata_block:
    default_contexts: [cms]
    blocks:
        sonata.admin.block.admin_list:
            contexts: [admin]

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

sonata_media:
    providers:
        image:
            resizer: sonata.media.resizer.square

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

【讨论】:

以上是关于Sonata Media Bundle 安装错误的主要内容,如果未能解决你的问题,请参考以下文章

使用 MongoDB 配置 Sonata Media Bundle 的问题

Sonata Media Bundle Custom Provider 未映射请求数据

如何正确删除使用 sonata-media-bundle 上传的所有图像

Symfony2 Sonata Media Bundle -- 上传图片时出错

集成 Sonata Media Bundle(媒体实体)和 Sonata Classiffication Bundle(标签实体)

Sonata Media Bundle 与 Sonata Admin Bundle 3.0(或 2.4)