gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 06:02:18 25 4
gpt4 key购买 nike

我正在尝试获取 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.我想知道为什么。

我是否采用了正确的方式使其工作,还是应该手动定义我的实体,然后尝试从中创建我的表?

最佳答案

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

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

更多在 docs .

关于php - 基于模式声明使用 Doctrine2 创建表和实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8795338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com