使用Doctrine2基于模式声明创建表和实体

时间:2012-01-09 21:19:20

标签: php zend-framework orm command-line doctrine-orm

我想让Doctrine2Zend Framework一起工作。到目前为止,我已经能够自动加载Doctrine2并连接到我的数据库。

我现在期待使用yml中的模式声明创建我的表:

Doctrine\Entities\User:
    type: entity
    table: core_user
    columns:
        id:
            primary: true
            autoincrement: true
            type: integer(11)
            notnull: true
        name:
            type: string
            notnull: true
            default: ''
        middle_name:
            type: string
            default: ''
        last_name:
            type: string
            notnull:true
            default: ''
        username:
            type: varchar(16)
            default: ''
        email:
            type: string
            notnull: true
            default: ''
        role_id:
            type: integer
        date_creation:
            type: timestamp
        version:
            type: timestamp

我能够让命令行工作,但我无法在数据库中创建表。

我使用的是标准Zend Framework文件夹结构

+-- Application
      +-- configs
      +-- controllers
      +-- doctrine
          +-- Schema
              +-- schema.yml
          +-- Entities
          cli-config.php
      +-- layouts
      +-- models
      +-- modules
      +-- view
      bootstrap.php
+-- Public
+-- Library
      +-- Doctrine2
+-- Tests

我的架构声明位于Application/doctrine/Schema/schema.yml,我希望从中创建我的数据库tablesEntities

当我尝试运行命令doctrine orm:schema-tool:create时,我收到以下消息:No Metadata Classes to process.我想知道原因。

我是否正确地使用它,或者我应该手动定义我的实体然后尝试从中创建我的表?

1 个答案:

答案 0 :(得分:3)

检查cli-config.php中的配置。 你应该使用YAML驱动程序:

// $config instanceof Doctrine\ORM\Configuration
$driver = new YamlDriver(array('/path/to/files'));
$config->setMetadataDriverImpl($driver);

更多docs