Symfony 3.4没有元数据类来处理错误
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Symfony 3.4没有元数据类来处理错误相关的知识,希望对你有一定的参考价值。
我已经安装了symfony 3.4和doctrine包
"php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.8",
"doctrine/doctrine-migrations-bundle": "^1.3",
"doctrine/orm": "^2.5",
"incenteev/composer-parameter-handler": "^2.0",
"sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^5.0.0",
"symfony/monolog-bundle": "^3.1.0",
"symfony/polyfill-apcu": "^1.0",
"symfony/swiftmailer-bundle": "^2.6.4",
"symfony/symfony": "3.4.*",
"twig/twig": "^1.0||^2.0"
使用以下命令创建数据库
php bin/console doctrine:database:create
G:XAMPPhtdocsproject>php bin/console doctrine:schema:validate
[Mapping] OK - The mapping files are correct.
[Database] OK - The database schema is in sync with the mapping files.
G:XAMPPhtdocsproject>php bin/console doctrine:schema:validate
[Mapping] OK - The mapping files are correct.
[Database] OK - The database schema is in sync with the mapping files.
G:XAMPPhtdocsproject>php bin/console doctrine:schema:update --force
No Metadata Classes to process.
G:XAMPPhtdocsproject>
每当我运行php bin / console doctrine:schema:update --force命令时,它会抛出一个错误
没有要处理的元数据类。
我在文档http://symfony.com/doc/3.4/doctrine.html中创建了实体类
产品实体类
<?php
namespace AppBundleEntity;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity
* @ORMTable(name="product")
*/
class Product
{
/**
* @ORMColumn(type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORMColumn(type="string", length=100)
*/
private $name;
/**
* @ORMColumn(type="decimal", scale=2)
*/
private $price;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return Product
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set price
*
* @param integer $price
*
* @return Product
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* Get price
*
* @return int
*/
public function getPrice()
{
return $this->price;
}
}
答案
是的,最后我发现问题是John.orm.php
文件,当我运行php bin/console doctrine:generate:entity
时会生成
我使用以下命令创建了Entity类
php bin/console doctrine:generate:entity
然后它会提示
Welcome to the Doctrine2 entity generator
This command helps you generate Doctrine2 entities.
First, you need to give the entity name you want to generate.
You must use the shortcut notation like AcmeBlogBundle:Post.
The Entity shortcut name: AppBundle:John
Determine the format to use for the mapping information.
Configuration format (yml, xml, php, or annotation) [annotation]: php
Instead of starting with a blank entity, you can add some fields now.
Note that the primary key will be added automatically (named id).
Available types: array, simple_array, json_array, object,
boolean, integer, smallint, bigint, string, text, datetime, datetimetz,
date, time, decimal, float, binary, blob, guid.
New field name (press <return> to stop adding fields): id
Field "id" is already defined.
New field name (press <return> to stop adding fields): username
Field type [string]: string
Field length [255]:
Is nullable [false]: true
Unique [false]: false
New field name (press <return> to stop adding fields): password
Field type [string]:
Field length [255]:
Is nullable [false]: true
Unique [false]:
New field name (press <return> to stop adding fields): dob
Field type [string]: date
Is nullable [false]: true
Unique [false]:
New field name (press <return> to stop adding fields):
Entity generation
created .srcAppBundle/Entity/John.php
created .srcAppBundle/Resources/config/doctrine/
created .srcAppBundle/Resources/config/doctrine/John.orm.php
> Generating entity class G:XAMPPhtdocsprojectsrcAppBundleEntityJohn.php:
OK!
> Generating repository class G:XAMPPhtdocsprojectsrcAppBundleRepositoryJ
ohnRepository.php: OK!
> Generating mapping file G:XAMPPhtdocsprojectsrcAppBundleResourcesconfig
doctrineJohn.orm.php: OK!
Everything is OK! Now get to work :).
G:XAMPPhtdocsproject>
成功之后,它将在AppBundleEntity;
的AppBundleRepository;
文件夹和存储库类中创建实体类,它还将在John.orm.php
中生成AppBundleResourcesconfigdoctrineJohn.orm.php
删除John.orm.php文件后,如果我运行php bin/console doctrine:schema:update --force
然后它将生成表。
另一答案
大多数时候由于实体路径问题和缓存而出现此错误。实体php文件必须位于您的特定文件夹中。通常我们通过命令生成实体:
doctrine:generate:entity
首先运行命令
doctrine:cache:clear-metadata
然后试试
以上是关于Symfony 3.4没有元数据类来处理错误的主要内容,如果未能解决你的问题,请参考以下文章
学习日记0827异常处理 元类 自定义元类 自定义元类来实例化类 属性查找顺序