Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
路径“”的类型无效;“mongodb.connections”原则;。应为数组,但得到字符串_Mongodb_Symfony_Doctrine_Setter_Getter - Fatal编程技术网

路径“”的类型无效;“mongodb.connections”原则;。应为数组,但得到字符串

路径“”的类型无效;“mongodb.connections”原则;。应为数组,但得到字符串,mongodb,symfony,doctrine,setter,getter,Mongodb,Symfony,Doctrine,Setter,Getter,我是一个非常新的编码和这个网站,所以我很抱歉我会和/或不会犯错误 我试图为mongoDB生成setter和getter(使用symfony 3),但在控制台中键入 php C:\wamp64\www\test\app\console doctrine:mongodb:generate:documents MainBundle 我得到这个错误: [Symfony\Component\Config\Definition\Exception\InvalidTypeException]

我是一个非常新的编码和这个网站,所以我很抱歉我会和/或不会犯错误

我试图为mongoDB生成setter和getter(使用symfony 3),但在控制台中键入

php C:\wamp64\www\test\app\console doctrine:mongodb:generate:documents MainBundle
我得到这个错误:

[Symfony\Component\Config\Definition\Exception\InvalidTypeException]                  
  Invalid type for path "doctrine_mongodb.connections". Expected array, but got string
注意到关于yml的层次结构和缩进的主题,但找不到正确的答案。正如我所说,我是一个新手,不知道这个系统是如何工作的,所以如果有人有任何想法,这里可能会有什么问题,请与我分享。 这是我的config.yml文件:

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: services.yml }
    - { resource: "@MainBundle/Resources/config/services.yml" }

# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
    locale: en

framework:
    #esi:             ~
    #translator:      { fallbacks: ["%locale%"] }
    secret:          "%secret%"
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    #serializer:      { enable_annotations: true }
    templating:
        engines: ['twig']
    default_locale:  "%locale%"
    trusted_hosts:   ~
    trusted_proxies: ~
    session:
        # handler_id set to null will use layout session handler from php.ini
        handler_id:  ~
    fragments:       ~
    http_method_override: 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.root_dir%/data/data.db3"
        #   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 }

doctrine_mongodb:
  connections: default
  default:
      server: mongodb://localhost:27017
      options: {}
  default_database: test_database
  document_managers:
    default:
      auto_mapping: true

错误很明显-只需将
原则\u mongodb.connections
值更改为
数组

# app/config/config.yml
doctrine_mongodb:
    connections:
        default:
            server: mongodb://localhost:27017
            options:  {}

您缺少两个空格:

doctrine_mongodb:
  connections: default
  default: # <-- here
      server: mongodb://localhost:27017
      options: {}


另外,我看到您在配置文件的3/4中使用了4个空格缩进。我建议您在文件中的任何地方都使用相同的缩进,这样以后就不会有任何问题,而且结构看起来更加一致。

没有帮助,同样的错误也会发生:
code
[Symfony\Component\Config\Definition\Exception\InvalidTypeException]路径的类型无效“doctrine_mongodb.connections.0“。应为数组,但得到了stringcheck我的更新答案-它必须是数组,但也包含参数。这是另一个问题的答案。它连接到doctor.orm配置,因此错误很明显。在您的
doctor.orm.layout\u entity\u manager
服务中,您试图注入
doctor.orm.quote\u strategy.layout
服务,该服务未在您的服务配置文件中定义,它不存在,但这是另一个问题的问题,与此问题无关。好的,所以我不太确定该魔法是什么,但我在这里发现了这个想法:删除项目的/bin和/vendor文件夹,然后安装一个composer(如果没有安装composer,则安装php composer.phar)。此外,我运行了
php composer.phar更新原则/mongodb-odm原则/mongodb-odm bundle
,整个系统现在似乎工作正常。
doctrine_mongodb:
  connections:
    default: # <-- indentation added here
      server: mongodb://localhost:27017
      options: {}
  default_database: test_database
  document_managers:
    default:
      auto_mapping: true