gpt4 book ai didi

mongodb - 路径 "doctrine_mongodb.connections"的类型无效。预期的数组,但得到了字符串

转载 作者:可可西里 更新时间:2023-11-01 10:23:42 28 4
gpt4 key购买 nike

我对编码和这个网站还很陌生,所以对于我会和/或不会犯的错误,我深表歉意。

我正在尝试为 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

最佳答案

您缺少 2 个空格缩进:

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

并且您不需要像这样为 connections 指定 default 值:connections: default 但它应该是一个数组.

所以有效的配置应该是:

doctrine_mongodb:
connections:
default: # <-- indentation added here
server: mongodb://localhost:27017
options: {}
default_database: test_database
document_managers:
default:
auto_mapping: true

参见 configuration reference .

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

关于mongodb - 路径 "doctrine_mongodb.connections"的类型无效。预期的数组,但得到了字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35959728/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com