Symfony 2 - 属性中的注释不存在,或者无法自动加载.

M M*_*ero 6 php doctrine symfony

我正在做symfony 2教程 - Doctrine和数据库.

我在Entity/Pages.php中创建了Pages.php文件

<?php
namespace Dproc\MainBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @IgnoreAnnotation("fn")
 *
 */
/**
 * @ORM\Entity
 * @ORM\Table(name="pages")
 */
class Pages
{
    /**
     * @ORM\ID
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $ID;

    /**
     * @ORM\Column(type="text")
     */
    protected $page_title;

    /**
     * @ORM\Column(type="text")
     */
    protected $page_content;

    /**
     * @ORM\Column(type="text")
     */
    protected $page_category;
}
Run Code Online (Sandbox Code Playgroud)

现在我正在尝试使用此命令为此类生成setter和getter.

php app/console doctrine:generate:entities Dproc/MainBundle/Entity/Pages
Run Code Online (Sandbox Code Playgroud)

它说 :

[Doctrine\Common\Annotations\AnnotationException]                            
  [Semantical Error] The annotation "@Doctrine\ORM\Mapping\ID" in property Dp  
  roc\MainBundle\Entity\Pages::$ID does not exist, or could not be auto-loade  
  d. 
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

小智 10

使用以下代码更改您的$ ID:

/**
 * @var integer
 *
 * @ORM\Column(type="integer", nullable=false)
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
private $id;
Run Code Online (Sandbox Code Playgroud)

  • 变量的名称是次要的,您可以输入任何名称.但是,Doctrine的注释是区分大小写的,它将标识符识别为"Id" (2认同)