Zend 1.11 和 Doctrine 2 自动从现有数据库生成所需的一切
我是 ORM 新手,我真的很想学习它。我按照本教程成功地使用 Zend 1.11.x 安装了 Doctrine 2.1 的所有类和配置。
http://www.zendcasts.com/unit-testing- doctrine-2-entities/2011/02/ 它使用 Bisna 插件和doctrine脚本。
现在我的问题是他清楚地解释了如何通过学说类创建实体和表,但没有解释如何从现有数据库自动生成代理和存储库类,这有助于我选择、插入和更新。我总是使用 MySQL Workbench 创建数据库。
我还遵循了以下教程
http://www.zend.com/en/webinar/Framework/70170000000bSrG-webinar-zf-v-1-doctrine-v-2-20101214.flv
我的数据库太复杂了关系以各种可能的方式流动。如果我按照这些教程中解释的步骤进行操作,我将永远无法完成我的项目。任何人都可以解释一下如何在配置后开始使用 Doctrine。考虑到我已经有一个数据库并且我的模型文件夹是空的。我的文件夹结构如下。
C:/zf/library/Doctrine
C:/zf/library/Symfony
C:/zf/library/ZC -- (my model which should contain the proxies and repo of Doctrine. At the moment it contains nothing.)
C:/zf/library/Zend
C:/zf/scripts/doctrine.php
请帮我!
我昨天发了同样的帖子,但没有人回复我的帖子。如果您需要我提供更多信息,请告诉我。
谢谢你,
卡西克
I am new to ORM and I am really keen to learn it. I successfully managed to install all classes and configurations for Doctrine 2.1 with Zend 1.11.x by following this tutorial.
http://www.zendcasts.com/unit-testing-doctrine-2-entities/2011/02/ Which uses Bisna plugin and doctrine scripts.
Now my problem is he is clearly explaining how to create entities and tables through doctrine classes but do not explain how to auto generate the proxies and repo classes from already existing database which helps me to select, insert and update. I always create my databases using MySQL Workbench.
I also followed the below tutorial as well
http://www.zend.com/en/webinar/Framework/70170000000bSrG-webinar-zf-v-1-doctrine-v-2-20101214.flv
My database is so complex with relationship flowing across every possible way. If I follow the steps which is explained in these tutorials I will never complete my project. Can any one please explain how to start using Doctrine after configuration. Considering I already have a database and my Model folders are empty. I have my folder sructure as below.
C:/zf/library/Doctrine
C:/zf/library/Symfony
C:/zf/library/ZC -- (my model which should contain the proxies and repo of Doctrine. At the moment it contains nothing.)
C:/zf/library/Zend
C:/zf/scripts/doctrine.php
Please help me!
I posted this same post yesterday and no one replied to my post. Please let me know if you need anymore information from me.
Thank you,
Karthik
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 Doctrine,您应该首先自己创建实体,然后从这些实体创建数据库模式。
但因为您已经有一个数据库,所以您可能不想要这样。可以将数据库转换为 PHP、XML 或 Yaml 格式的 Doctrine2 实体。
您应该仔细查看 Doctrine 与 Bisna 胶水一起提供的命令行工具,因为在那里您可以生成很多东西。
要从数据库生成实体,请考虑以下命令:
您还可以定义实体必须扩展的命名空间和基类:--namespace=namespace 和 --extends=class。
Doctrine2 警告您将数据库转换为实体,因为并非所有内容都可以自动检测或支持。例如,Doctrine2 默认情况下不支持 ENUM 数据类型,因此转换数据库会引发错误。
在使用所有实体之前,最好检查它们,尤其是关联。希望对您有帮助。
According to Doctrine you should create your entities first yourself and then create your database schema from these entities.
But because you already have a database you probably don't want that. It is possible to convert your database to Doctrine2 entities in PHP, XML or Yaml.
You should take a closer look at the commandline tools Doctrine offers with the Bisna glue because there you can generate a lot of stuff.
To generate your entities FROM your database consider the following command:
You can also define the namespace and a base class which your entities have to extends with: --namespace=namespace and --extends=class.
Doctrine2 warns you to convert your database to entities because not everything could be auto detected or supported. For instance ENUM datatypes are not supported by default in Doctrine2 so converting your database will raise an error.
It's a good idea to check all your entities especially associations before you use them. Hope it helps you.
如果我正确理解您的问题,那么您已经配置了实体,并且需要自动生成代理和存储库类。
两者都可以使用应用程序根目录中的以下 Doctrine CLI 命令创建:
如果您正在寻找一种自动生成实体类的方法,不幸的是,我认为目前还没有可用的解决方案。
ORM Designer 的支持代表表示,他们正在“开发”此功能,并且“非常需要” ”。希望它能被包含在 ORM Designer 2.0 中,因为编码/映射实体类通常涉及大量重复性工作,而这些工作可能会被自动化。
If I understand your question correctly, you have your entities already configured and need to auto-generate your proxy and repository classes.
Both can be created using the following Doctrine CLI commands from your application's root directory:
If you're looking for a way to auto-generate your entity classes, unfortunately I don't think a solution is available for this yet.
A support rep at ORM Designer said they are "working on" this feature and that it is "very demanded." Here's hoping it will be included in ORM Designer 2.0 since there is generally a lot of repetitive work involved in coding/mapping entity classes that could likely be automated.
如果您以 XML 或 YAML 格式提供映射信息,则可以使用
orm:generate-entities
命令。请参阅http://www.doctrine- project.org/docs/orm/2.1/en/reference/tools.html#entity- Generation
对于开发,请在配置中将代理生成设置为自动,否则,请使用
orm:generate-proxies
命令。除非您需要自定义存储库,否则会根据请求在实体管理器中创建通用存储库。要指定自定义存储库,只需使用
repository-class
实体映射属性。请参阅 http:// www.doctrine-project.org/docs/orm/2.1/en/reference/xml-mapping.html#defining-an-entity 为例
You can use the
orm:generate-entities
command if you provide mapping information in either XML or YAML format.See http://www.doctrine-project.org/docs/orm/2.1/en/reference/tools.html#entity-generation
For development, set proxy generation to be automatic in your config, otherwise, use the
orm:generate-proxies
command.Unless you need to customise your repositories, generic ones are created in the entity manager when requested. To specify custom repositories, simply use the
repository-class
entity mapping attribute.See http://www.doctrine-project.org/docs/orm/2.1/en/reference/xml-mapping.html#defining-an-entity for an example