路径 "doctrine_mongodb.connections" 的类型无效。预期的数组,但得到了字符串
Invalid type for path "doctrine_mongodb.connections". Expected array, but got string
我对编码和这个网站还很陌生,所以对于我 and/or 不会犯的错误,我深表歉意。
我正在尝试为 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
错误很明显 - 只需将 doctrine_mongodb.connections
值更改为 array
。
# app/config/config.yml
doctrine_mongodb:
connections:
default:
server: mongodb://localhost:27017
options: {}
您缺少 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 个空格缩进。我建议你在文件中的所有地方都使用相同的缩进,这样你以后就不会遇到任何麻烦,而且结构看起来更一致。
我对编码和这个网站还很陌生,所以对于我 and/or 不会犯的错误,我深表歉意。
我正在尝试为 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
错误很明显 - 只需将 doctrine_mongodb.connections
值更改为 array
。
# app/config/config.yml
doctrine_mongodb:
connections:
default:
server: mongodb://localhost:27017
options: {}
您缺少 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 个空格缩进。我建议你在文件中的所有地方都使用相同的缩进,这样你以后就不会遇到任何麻烦,而且结构看起来更一致。