【问题标题】:Create tables and entities with Doctrine2 based on schema declaration基于模式声明使用 Doctrine2 创建表和实体
【发布时间】:2012-02-06 09:30:32
【问题描述】:

我正在努力让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 中,我希望从中创建我的数据库tables 和我的Entities

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

我是否以正确的方式让它工作,或者我应该手动定义我的实体,然后尝试从中创建我的表?

【问题讨论】:

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


    【解决方案1】:

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

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

    docs 中的更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-22
      • 1970-01-01
      • 1970-01-01
      • 2014-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多