【发布时间】:2018-01-09 12:32:38
【问题描述】:
我正在关注Doctrine Getting Started 教程。
我已经创建了 Product 类(通过从教程中复制/粘贴,以确保没有拼写错误),但是当我运行时
vendor/bin/doctrine orm:schema-tool:create
我收到[OK] No Metadata Classes to process。这似乎是因为Setup::createAnnotationMetadataConfiguration 的useSimpleAnnotationReader 参数默认为true。
所以如果我把它改成false:
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode, null, null, false);
运行上面的schema-tool:create 命令现在返回:
[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The annotation "@Doctrine\ORM\Annotation\Entity" in class Product does not exist, or could not be auto-loaded.
什么时候应该执行,然后转储生成的 SQL。
在 SO 和其他地方搜索,似乎这个问题通常是由于在注释中使用正斜杠而不是反斜杠(我没有)或产品实体中的其他拼写错误(我复制/粘贴)引起的,或将 Doctrine 用作更广泛框架(Zend、Symfony)的一部分。
我的Product.php:
<?php
// src/Product.php
use Doctrine\ORM\Annotation as ORM;
/**
* @ORM\Entity @ORM\Table(name="products")
**/
class Product
{
/** @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue **/
protected $id;
/** @ORM\Column(type="string") **/
protected $name;
public function getId()
{
return $this->id;
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
}
【问题讨论】:
标签: php doctrine-orm orm doctrine