我需要在哪里添加此代码,以便在使用zend framework 2的doctrine 2中将命名策略更改为UnderscoreNamingStrategy
$namingStrategy = new MyNamingStrategy();
$configuration()->setNamingStrategy($namingStrategy);
我没有yaml文件。
答案 0 :(得分:0)
以下是一个例子:
use Doctrine\Common\Annotations\AnnotationReader,
Doctrine\Common\Cache\ArrayCache,
Doctrine\ORM\Configuration,
Doctrine\ORM\EntityManager,
Doctrine\ORM\Mapping\Driver\AnnotationDriver;
$config = new Configuration;
$config->setMetadataCacheImpl(new ArrayCache());
$driverImpl = new AnnotationDriver(new AnnotationReader(), '/path/to/entities');
$config->setMetadataDriverImpl($driverImpl);
$config->setNamingStrategy(new MyNamingStrategy());
$connectionOptions = array(
'url' => 'sqlite:///:memory:'
);
$this->entityManager = EntityManager::create($connectionOptions, $config);
答案 1 :(得分:0)
将此内容包含在您的module.config.php
中<?php
use Doctrine\ORM\Mapping\UnderscoreNamingStrategy;
use Zend\ServiceManager\Factory\InvokableFactory;
return [
'doctrine' => [
'configuration' => [
'orm_default' => [
'naming_strategy' => UnderscoreNamingStrategy::class,
],
],
],
'service_manager' => [
'factories' => [
UnderscoreNamingStrategy::class => InvokableFactory::class,
],
],
];