【发布时间】:2011-11-14 07:19:16
【问题描述】:
我将 Doctrine 与 Zend 框架一起使用。我必须使用注释创建 DB 模式和 Doctrine 实体。
由于注释已经包含信息,因此应该可以基于它们创建/更新架构。我不想重新发明轮子,所以我想知道这种逻辑是否已经存在?
【问题讨论】:
标签: zend-framework doctrine doctrine-orm
我将 Doctrine 与 Zend 框架一起使用。我必须使用注释创建 DB 模式和 Doctrine 实体。
由于注释已经包含信息,因此应该可以基于它们创建/更新架构。我不想重新发明轮子,所以我想知道这种逻辑是否已经存在?
【问题讨论】:
标签: zend-framework doctrine doctrine-orm
您可以使用学说 CLI 来完成许多与学说相关的任务。我不确定教义是如何集成到 Zend 中的,但请查找教义.php,然后像这样调用它:
php doctrine.php orm:schema-tool:update --force
这将更新您的数据库以匹配您的架构定义。你也可以使用
php doctrine.php orm:schema-tool:update --dump-sql
查看学说会运行哪些 SQL 命令。有关详细信息,请参阅教义文档中的 Tools section。
【讨论】:
有 Doctrine SchemaTool (ORM/Tools/SchemaTool)。
$meta = array(
$this->_em->getClassMetadata('Customer')
);
$tool = new \Doctrine\ORM\Tools\SchemaTool($this->_em);
$tool->updateSchema($meta);
【讨论】: