我对编码和这个网站还很陌生,所以我对我会犯和/或不会犯的错误感到抱歉。
我正在尝试为 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
此外,我发现您在配置文件的 3/4 中使用了 4 个空格缩进。我建议您在文件中的所有位置使用相同的缩进,这样您将来就不会遇到任何麻烦,而且结构看起来会更加一致。
关于mongodb - 路径 "doctrine_mongodb.connections"的类型无效。需要数组,但得到字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35959728/