教义2.3实体生成器:样本,文档? [英] Doctrine 2.3 Entity Generator: samples, docs?

查看:118
本文介绍了教义2.3实体生成器:样本,文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原则可以基于小数据输入生成实体,包括关系信息。但是,我没有找到关于该主题的任何示例或简明扼要的信息。官方文档只有一个小段落,有一个小命令行示例,绝对没有解释,



任何人都可以参考一本书,文章甚至代码示例?

解决方案

首先你需要 bootstrap Doctrine 并获取一个 EntityManager 的实例,那么你一旦你可以执行以下操作:

  $ cmf = new Doctrine\ORM\Tools\DisconnectedClassMetadataFactory(); 
$ cmf-> setEntityManager($ em); // $ em是EntityManager实例
$ metadata = $ cmf-> getAllMetadata();
$ generator = new \Doctrine\ORM\Tools\EntityGenerator();
$ generator-> setGenerateAnnotations(true);
$ generator-> setGenerateStubMethods(true);
$ generator-> setRegenerateEntityIfExists(true);
$ generator-> setUpdateEntityIfExists(false);
$ generator-> generate($ metadata,'/ path / to / entities');

有关配置的更多信息,请阅读:

http://docs.doctrine-project.org/projects/ doctrine-orm / en / latest / reference / configuration.html


Doctrine can generate entities based on small data input, including relation information. However, i have failed to find any example or concise information on the topic. The official documentation only has a small paragraph, with a minor command line example, explaining absolutely nothing,

Can anyone refer to a book, article or even code sample of this?

解决方案

First you need to bootstrap Doctrine and get an instance of EntityManager, then you once you have it, you can do the following:

    $cmf = new Doctrine\ORM\Tools\DisconnectedClassMetadataFactory();
    $cmf->setEntityManager($em); // $em is EntityManager instance
    $metadata = $cmf->getAllMetadata();
    $generator = new \Doctrine\ORM\Tools\EntityGenerator();
    $generator->setGenerateAnnotations(true);
    $generator->setGenerateStubMethods(true);
    $generator->setRegenerateEntityIfExists(true);
    $generator->setUpdateEntityIfExists(false);
    $generator->generate($metadata, '/path/to/entities');

For more information on the configuration, read this:
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/configuration.html

这篇关于教义2.3实体生成器:样本,文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆