[英]Doctrine2 mapping enum
I'm writing my own CMS with Doctrine 2.5.4 and pure php 5. while building, i countered this error: 我在构建时使用Doctrine 2.5.4和纯PHP 5编写自己的CMS,但我遇到了以下错误:
Fatal error: Uncaught exception 'Doctrine\\DBAL\\DBALException' with message 'Unknown database type enum requested, Doctrine\\DBAL\\Platforms\\MySqlPlatform may not support it.'
致命错误:消息为“请求了未知的数据库类型枚举,Doctrine \\ DBAL \\ Platforms \\ MySqlPlatform可能不支持”的未捕获异常'Doctrine \\ DBAL \\ DBALException'。 in /var/www/html/xxxx.com/public_html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php:423 Stack trace: #0 /var/www/html/xxxx.com/public_html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php(126): Doctrine\\DBAL\\Platforms\\AbstractPlatform->getDoctrineTypeMapping('enum') #1 /var/www/html/xxxxx.com/public_html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php(820): Doctrine\\DBAL\\Schema\\MySqlSchemaManager->_getPortableTableColumnDefinition(Array) #2 /var/www/html/xxxx.com/public_html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php(175): Doctrine\\DBAL\\Schema\\AbstractSchemaManager->_getPortableTableColumnList('bonus_top_....', 'xxxx', Array) #3 /var/www/html/xxxx.com/public_html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php(281) in /var/www/html/xxxx.com/public_html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php on line 423 my config.php:
在/var/www/html/xxxx.com/public_html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php:423堆栈跟踪中:#0 /var/www/html/xxxx.com/public_html /vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php(126):Doctrine \\ DBAL \\ Platforms \\ AbstractPlatform-> getDoctrineTypeMapping('enum')#1 /var/www/html/xxxxx.com/ public_html / vendor / doctrine / dbal / lib / Doctrine / DBAL / Schema / AbstractSchemaManager.php(820):Doctrine \\ DBAL \\ Schema \\ MySqlSchemaManager-> _ getPortableTableColumnColumnDefinition(Array)#2 /var/www/html/xxxx.com/public_html /vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php(175):Doctrine \\ DBAL \\ Schema \\ AbstractSchemaManager-> _ getPortableTableColumnColumnList('bonus_top _....,'xxxx',Array)#3 / var / www / html / xxxx.com / public_html / vendor / doctrine /中的var / www / html / xxxx.com / public_html / vendor / doctrine / dbal / lib / Doctrine / DBAL / Schema / AbstractSchemaManager.php(281)第423行上的dbal / lib / Doctrine / DBAL / Platforms / AbstractPlatform.php我的config.php:
<?php
ini_set("display_errors",true);
date_default_timezone_set("Asia/Hongkong");
define('TIMER_START', microtime( true ) );
define('DS', DIRECTORY_SEPARATOR );
define('ROOT_DIR', realpath( dirname( __FILE__ ) ). DS );
define('DAODIR', ROOT_DIR.'DAO'.DS );
define('MNGDIR', ROOT_DIR.'manager'.DS );
define('HDLDIR' , ROOT_DIR.'handler'.DS );
define('TPLDIR', ROOT_DIR.'template'.DS );
define('SKNDIR', TPLDIR.'skin'.DS );
define('MDLDIR', ROOT_DIR.'model'.DS );
define('DBN', 'xxxx' );
define('HOST', 'xxxx' );
define('USR', 'xxxx' );
define('PWD','xxxx');
require_once "vendor/autoload.php";
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
$paths = array(MDLDIR);
$isDevMode = false;
// the connection configuration
$dbParams = array(
'driver' => 'pdo_mysql',
'host' => HOST,
'user' => USR,
'password' => PWD,
'dbname' => DBN,
'charset' =>'utf8',
);
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$em = EntityManager::create($dbParams, $config);
?>
and my news.php 和我的news.php
<?php
/**
* @Entity @Table(name="news")
*/
class News{
/**
* @nid @Column(type="integer") // **my id column is nid**
* @GeneratedValue
*/
public $id;
/** @author @Column(type="string")*/
public $author;
/** @date @Column(type="integer")*/
public $date;
/** @title @Column(type="string")*/
public $title;
/**@content @Column(type="text")*/
public $content;
/**@full @Column(type="text")*/
public $full;
/**@title_en @Column(type="string")*/
public $title_en;
/**@content_en @Column(type="text")*/
public $content_en;
/**@full_en @Column(type="text")*/
public $full_en;
/**@flink @Column(type="text")*/
public $flink;
/**@img @Column(type="text")*/
public $img;
}
?>
my table news
in mysql: 我在mysql中的表格
news
:
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| nid | int(11) | NO | PRI | NULL | auto_increment |
| author | varchar(50) | NO | | | |
| date | int(11) | NO | | 0 | |
| title | varchar(255) | NO | | | |
| content | text | NO | | NULL | |
| full | text | NO | | NULL | |
| title_en | varchar(255) | NO | | | |
| content_en | text | NO | | NULL | |
| full_en | text | NO | | NULL | |
| flink | text | NO | | NULL | |
| img | text | NO | | NULL | |
+------------+--------------+------+-----+---------+----------------+
I tried to fix as this article but did not work. 我试图解决本文的问题,但没有成功。 I did as this link for setup doctrine.
我将其作为设置学说的链接 。 I really have no idea why.
我真的不知道为什么。 Please help me.
请帮我。 Thanks in advance.
提前致谢。
P/s: I don't use any strange type like enum....(newbie T_T). P / s:我不使用任何奇怪的类型,例如enum ....(新手T_T)。
Due to the database is my company not mine, I did not know that doctrine would scan all my database but not as i did for config ( only a datat able for demo). 由于数据库不是我的公司,我不知道该准则会扫描我的所有数据库,但不会像我对config所做的那样扫描(仅可用于演示的datat)。 When i noticed that the error noticed me another table.
当我注意到该错误通知我另一个表时。
_getPortableTableColumnList('bonus_top_....', 'xxxx', Array) #3
So i did fix this table, which has enum type. 所以我确实修复了此表,该表具有枚举类型。 In vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php add
"enum" => 'string'
在vendor / doctrine / dbal / lib / Doctrine / DBAL / Platforms / MySqlPlatform.php中添加
"enum" => 'string'
Thank everyone. 谢谢大家 And sorry for making troubling.
很抱歉造成麻烦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.