1、安装好doctrine,在composer.json中添加如下

    "require": {
"php": "^5.6 || ^7.0",
"doctrine/doctrine-orm-module": "*",
},

执行composer install

2、在yourAPP/config/modules.config.php添加doctrine module

return [
'Zend\ServiceManager\Di',
'Zend\Session',
'Zend\Mvc\Plugin\Prg',
'Zend\Mvc\Plugin\Identity',
'Zend\Mvc\Plugin\FlashMessenger',
'Zend\Mvc\Plugin\FilePrg',
'Zend\Mvc\I18n',
'Zend\Mvc\Console',
'Zend\Log',
'Zend\Form',
'Zend\Db',
'Zend\Cache',
'Zend\Router',
'Zend\Validator',
'ZendDeveloperTools',
'Application',
'DoctrineModule',
'DoctrineORMModule',
];

3、在yourAPP/config/autoload/local.php添加如下

<?php
/**
* Local Configuration Override
*
* This configuration override file is for overriding environment-specific and
* security-sensitive configuration information. Copy this file without the
* .dist extension at the end and populate values as needed.
*
* @NOTE: This file is ignored from Git by default with the .gitignore included
* in ZendSkeletonApplication. This is a good practice, as it prevents sensitive
* credentials from accidentally being committed into version control.
*/
use Doctrine\DBAL\Driver\PDOMySql\Driver as PDOMySqlDriver;
return [
'doctrine' => [
'connection' => [
'orm_default' => [
'driverClass' => PDOMySqlDriver::class,
'params' => [
'host' => '10.11.1.2',
'port' => '',
'user' => 'xxx',
'password' => 'xxx',
'dbname' => 'user_shanmaohuwai',
]
],
],
],
];

4、使用doctrine命令生成entity(https://www.e-learn.cn/content/wangluowenzhang/609311)

问题:

I am using "doctrine/doctrine-orm-module": "0.7.0" with ZF2.

Once I create Entities I usually run following commands to sync and generate database automatically according to my entities.

./vendor/bin/doctrine-module orm:validate-schema
./vendor/bin/doctrine-module orm:schema-tool:create

Is there a way to make this process reverse? I mean, Can I generate entities from existing database in mysql?

回答1:

We use a batch script:

@ECHO OFF

mkdir EXPORT
call .\vendor\bin\doctrine-module orm:convert-mapping --force --from-database annotation ./EXPORT/
call .\vendor\bin\doctrine-module orm:generate-entities ./EXPORT/ --generate-annotations=true pause

orm:convert-mapping and orm:generate-entities is probably what you are looking for.

回答2:

There's a nice blog written on this here

Edit: It can be done by using the commands below:
1. convert-mapping (Table & Entity):

./vendor/doctrine/doctrine-module/bin/doctrine-module orm:convert-mapping --namespace="Album\\Entity\\" --force  --from-database annotation ./module/Album/src/

2. Generates getter and setter

./vendor/doctrine/doctrine-module/bin/doctrine-module orm:generate-entities ./module/Album/src/ --generate-annotations=true

回答3:

Try just it

doctrine orm:convert-mapping -f --from-database annotation entities/

doctrine orm:generate-entities --generate-annotations="true" entities/

http://wildlyinaccurate.com/useful-doctrine-2-console-commands/

cd appdir
./vendor/doctrine/doctrine-module/bin/doctrine-module orm:convert-mapping --namespace="Application\\Entity\\" --force --from-database annotation ./module/Application/src/
./vendor/doctrine/doctrine-module/bin/doctrine-module orm:generate-entities ./module/Application/src/ --generate-annotations=true

How to generate entities from database schema using doctrine-orm-module的更多相关文章

  1. database schema

    数据中有4个Schema无法被删除 ● dbo, 具有db_owner或者db_ddl_admin 的用户,新创建对象默认schema就是dbo ● guest , 用来给guest 用户使用,这个s ...

  2. Could not update Activiti database schema: unknown version from database: '5.20.0.1'

    转: Could not update Activiti database schema: unknown version from database: '5.20.0.1' 2017年11月22日 ...

  3. Create schema error (unknown database schema '')

    Andrey Devyatka 4 years ago Permalink Raw Message Hi,Please tell me, can I use the static library in ...

  4. [odb-users] Create schema error (unknown database schema '')

    Boris Kolpackov boris at codesynthesis.comFri May 31 11:13:02 EDT 2013 Previous message: [odb-users] ...

  5. PostgreSQL中,database,schema,table之间关系

    从逻辑上看,schema,table,都是位于database之下. 首先,在postgres数据库下建立表(相当于建立在public schema下): [pgsql@localhost bin]$ ...

  6. 改善database schema

    本文地址:http://blog.csdn.net/sushengmiyan/article/details/50422102 本文作者:苏生米沿 Hibernate 读取你java模型类的映射元数据 ...

  7. openfire 安装配置时出现The Openfire database schema does not appear to be installed. Follow the installati错误的解决方案

    最近再弄openfire用openLDAP整合,本来没整合的时候选的标准数据库没问题,但是现在用嵌入式数据库,就报错了,,, 报错原因:没有导入openfire的数据表 解放办法: 1.登陆数据库 , ...

  8. Could not update Activiti database schema: unknown version from database: '5.22.x.x'

    原因:activiti 相关的jar版本和表 act_ge_property 中 schema.version 所存储的版本不一致导致报错的. 查看activiti 相关jar版本 然后修改表中的版本 ...

  9. Database Schema Reader

    数据架构与INSERT脚本生成 https://dbschemareader.codeplex.com/wikipage?title=Writing%20Data&referringTitle ...

随机推荐

  1. pyppeteer基本使用demo

    # -*- coding: utf-8 -*- # 类似selenium,支持异步,不需要再单独安装环境,pyppeteer自动安装环境 # 异步await要写到一个函数的内部 from pyppet ...

  2. element UI中的tab切换栏

    html代码:(用的是el-tab组件) <el-tabs v-model="activeIndex" type="border-card" @tab-c ...

  3. 每天都在用 Map,这些核心技术你知道吗?

    本篇文章站在多线程并发安全角度,带你了解多线程并发使用 HashMap 将会引发的问题,深入学习 ConcurrentHashMap ,带你彻底掌握这些核心技术. 全文摘要: HashMap 核心技术 ...

  4. 如何使用Logstash

    目录 一.什么是Logstash 二.如何安装 三.快速使用 四.Input输入插件 五.codec编码插件 六.filter过滤器插件 七.output输出插件 八.总结 一.什么是Logstash ...

  5. 第3章 C++中的C

    用union节省内存 使用场合:有时一个程序会使用同一个变量处理不同的数据类型,对于这种情况,有两种选择:可以创建一个struct,其中包含所有可能的不同类型的数据:也可以使用联合union,它能把所 ...

  6. 用纯Python实现循环神经网络RNN向前传播过程(吴恩达DeepLearning.ai作业)

    Google TensorFlow程序员点赞的文章!   前言 目录: - 向量表示以及它的维度 - rnn cell - rnn 向前传播 重点关注: - 如何把数据向量化的,它们的维度是怎么来的 ...

  7. js运算【按位非】~ (index = ~~this.userIndex)(~~ 双破折号 如果是数字返回数字,如果不是数字 返回0)

    index = ~~this.userIndex ~~ 双破折号 如果是数字返回数字,如果不是数字 返回0 这个运算符有点意思:按位非[~] 先来几个例子: ~undefined: -1 ~false ...

  8. Java与C语言的区别——含面向对象介绍

    很多初学编程的小伙伴或者想要学习编程的小白弄不清C语言和Java的区别.本文就针对萌新们尽量用通俗的语言来介绍一下我所理解的编程语言界的两大巨头. 为什么说是两巨头,介绍之前我们先看一下某度搜索出来的 ...

  9. vue 2

    目录 复习 今日 指令 条件指令 循环指令 评论案例 解决插值表达式符号冲突 总结 组件 局部组件 全局组件 组件间的交互:父传子 组件间的交互:子传父 复习 """ 1 ...

  10. no parameterless constructor define for type 解决一例

    在生成根据模型和上下文生成带增删查改操作的视图的控制器时,提示上述信息,网上查找了资料也没有解决,突然想起该项目是连接MSSQL数据库和Redis数据库的,并且已经依赖注入了,而Redis数据库的服务 ...