【发布时间】:2016-03-19 16:31:15
【问题描述】:
这可能是一个新手问题,在 Symfony 的文档中我找不到它。我已经根据文档安装了 Symfony,并使用“数据库和学说”手册创建了一个数据库。之后,我使用该学说创建了一个实体。当我这样做时,我注意到没有创建注释。作为捆绑包,我使用了 AppBundle,它也在我的 AppKernel 中,如下所示:
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new AppBundle\AppBundle(),
];
更新:
使用命令 php bin/console doctrine:generate:entity 我使用注释(而不是 yml、php 或 xml)创建了实体 Foo,结果如下:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Foo
*
* @ORM\Table(name="foo")
* @ORM\Entity(repositoryClass="AppBundle\Repository\FooRepository")
*/
class Foo
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="bar", type="string", length=35)
*/
private $bar;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set bar
*
* @param string $bar
*
* @return Foo
*/
public function setBar($bar)
{
$this->bar = $bar;
return $this;
}
/**
* Get bar
*
* @return string
*/
public function getBar()
{
return $this->bar;
}
}
所以它也生成了注释,但我仍然无法生成我的数据库模式:(
下面的原始问题已过时 我必须手动输入注释的原因是什么?
【问题讨论】:
标签: php symfony doctrine-orm annotations