我是 ORM 的新手,我真的很想学习它.按照本教程,我成功地使用 Zend 1.11.x 安装了 Doctrine 2.1 的所有类和配置.
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/ 使用 Bisna 插件和学说脚本.
http://www.zendcasts.com/unit-testing-doctrine-2-entities/2011/02/ Which uses Bisna plugin and doctrine scripts.
现在我的问题是他清楚地解释了如何通过学说类创建实体和表,但没有解释如何从已经存在的数据库中自动生成代理和 repo 类,这有助于我选择、插入和更新.我总是使用 MySQL Workbench 创建数据库.
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
我的数据库非常复杂,关系通过各种可能的方式流动.如果我按照这些教程中解释的步骤进行操作,我将永远无法完成我的项目.谁能解释一下配置后如何开始使用Doctrine.考虑到我已经有一个数据库并且我的模型文件夹是空的.我的文件夹结构如下.
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
请帮帮我!
我昨天发布了同样的帖子,没有人回复我的帖子.如果您需要我提供更多信息,请告诉我.
I posted this same post yesterday and no one replied to my post. Please let me know if you need anymore information from me.
谢谢你,
卡提克
根据 Doctrine,您应该首先自己创建实体,然后从这些实体创建数据库模式.
According to Doctrine you should create your entities first yourself and then create your database schema from these entities.
但是因为您已经有一个数据库,所以您可能不想要它.可以将您的数据库转换为 PHP、XML 或 Yaml 中的 Doctrine2 实体.
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.
您应该仔细看看 Doctrine 提供的带有 Bisna 胶水的命令行工具,因为在那里您可以生成很多东西.
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:
php doctrine.php orm:convert-mapping --from-database php ../library/Application/Entity
您还可以定义实体必须扩展的命名空间和基类:--namespace=namespace 和 --extends=class.
You can also define the namespace and a base class which your entities have to extends with: --namespace=namespace and --extends=class.
Doctrine2 警告您将数据库转换为实体,因为并非所有内容都可以自动检测或支持.例如,Doctrine2 默认不支持 ENUM 数据类型,因此转换数据库会引发错误.
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.
这篇关于Zend 1.11 和 Doctrine 2 自动从现有数据库生成所需的一切的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!