Zend 2 Framework - Doctrine 从给定的 2 个实体中生成一个表
Zend 2 Framework - Doctrine generates tables from one entity from 2 given
几天来我一直在使用 Zend 2,但遇到了一些小麻烦。我们正在使用学说,并尝试从实体生成数据库模式。我在每个模块中指定学说应该使用每个模块的 module.config.php 文件找到实体。目前我有 2 个模块和 2 个不同的 module.config 文件,这些是我指定 Doctrine 应该找到实体的路径的行:
module.config.php(邮件模板(模块))
'doctrine' => array(
'driver' => array(
'application_entities' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => (__DIR__ . '/../src/MailTemplates/Model')
),
'orm_default' => array(
'drivers' => array(
'MailTemplates\Model' => 'application_entities'
),
),
),
),
和module.config.php(应用程序(模块))
'doctrine' => array(
'driver' => array(
'application_entities' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => (__DIR__ . '/../src/Application/Entity')
),
'orm_default' => array(
'drivers' => array(
'Application\Entity' => 'application_entities'
),
),
),
),
);
当我执行从实体生成模式的命令时 (./vendor/bin/doctrine-module orm:schema-tool:create) 它只创建 MailTemplate 表,而忽略应用程序模块表。如果我注释掉 MailTemplate 模块的 module.config.php 行,并再次执行该命令,我可以看到来自应用程序模块实体的表已成功创建。所以我想不知何故来自 2 module.config 文件的信息被覆盖了。
我需要从不同模块的不同实体生成 DB shema,但我不知道怎么做。
谢谢!!
Zf2 module.config.php 文件未被覆盖。 zf2 将所有 module.config.php 合并到一个文件中。
Zend\ModuleManager\Listener\ConfigListener 触发一个特殊事件,Zend\ModuleManager\ModuleEvent::EVENT_MERGE_CONFIG,在合并所有配置之后,但在传递给 ServiceManager 之前。通过侦听此事件,您可以检查合并的配置并对其进行操作。
查看 zend 如何合并配置文件https://framework.zend.com/manual/2.4/en/tutorials/config.advanced.html#configuration-mapping-table
这是因为您为驱动程序设置了相同的名称。虽然 zend 合并了配置,但它会覆盖同名的配置。
module.config.php(邮件模板(模块))
[...]
'drivers' => array(
'MailTemplates\Model' => 'application_entities' <-- rename this
)
[..]
module.config.php(应用程序(模块))
[...]
'drivers' => array(
'Application\Entity' => 'application_entities'
)
[..]
几天来我一直在使用 Zend 2,但遇到了一些小麻烦。我们正在使用学说,并尝试从实体生成数据库模式。我在每个模块中指定学说应该使用每个模块的 module.config.php 文件找到实体。目前我有 2 个模块和 2 个不同的 module.config 文件,这些是我指定 Doctrine 应该找到实体的路径的行:
module.config.php(邮件模板(模块))
'doctrine' => array(
'driver' => array(
'application_entities' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => (__DIR__ . '/../src/MailTemplates/Model')
),
'orm_default' => array(
'drivers' => array(
'MailTemplates\Model' => 'application_entities'
),
),
),
),
和module.config.php(应用程序(模块))
'doctrine' => array(
'driver' => array(
'application_entities' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => (__DIR__ . '/../src/Application/Entity')
),
'orm_default' => array(
'drivers' => array(
'Application\Entity' => 'application_entities'
),
),
),
),
);
当我执行从实体生成模式的命令时 (./vendor/bin/doctrine-module orm:schema-tool:create) 它只创建 MailTemplate 表,而忽略应用程序模块表。如果我注释掉 MailTemplate 模块的 module.config.php 行,并再次执行该命令,我可以看到来自应用程序模块实体的表已成功创建。所以我想不知何故来自 2 module.config 文件的信息被覆盖了。
我需要从不同模块的不同实体生成 DB shema,但我不知道怎么做。
谢谢!!
Zf2 module.config.php 文件未被覆盖。 zf2 将所有 module.config.php 合并到一个文件中。
Zend\ModuleManager\Listener\ConfigListener 触发一个特殊事件,Zend\ModuleManager\ModuleEvent::EVENT_MERGE_CONFIG,在合并所有配置之后,但在传递给 ServiceManager 之前。通过侦听此事件,您可以检查合并的配置并对其进行操作。
查看 zend 如何合并配置文件https://framework.zend.com/manual/2.4/en/tutorials/config.advanced.html#configuration-mapping-table
这是因为您为驱动程序设置了相同的名称。虽然 zend 合并了配置,但它会覆盖同名的配置。
module.config.php(邮件模板(模块))
[...]
'drivers' => array(
'MailTemplates\Model' => 'application_entities' <-- rename this
)
[..]
module.config.php(应用程序(模块))
[...]
'drivers' => array(
'Application\Entity' => 'application_entities'
)
[..]