我创建了CompilerPass类,以将数据库中的某些数据设置为参数:
class ParametersCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$em = $container->get('doctrine.orm.default_entity_manager');
$params = $em->getRepository(Setting::class)->findAll();
}
}
但我收到此错误:
An exception occurred in driver: SQLSTATE[HY000] [1102] Incorrect database name 'nv_097f203e25c61d94_resolve_database_url_c9a61b2f5dc3b858f85dcd10be22549a'
当我获得实体经理时,例如通过doctrine.orm.default_entity_manager
服务在控制器中运行一切正常。
doctrine.yaml:
parameters:
env(DATABASE_URL): ''
doctrine:
dbal:
driver: 'pdo_mysql'
server_version: '5.4'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App