doujiu5464 2014-03-13 13:08
浏览 13

ZF2 doctrineORM实体需要两次

Got a zf2 skeleton app, with DoctrineORM with some entities, and all works fine.

Now when i try to add a "Category" entity:

namespace Me\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="me_category")
 */
class Category
{
    /**
     * @var int
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;


    /**
     * @var string
     * @ORM\Column(type="string", length=255, unique=true)
     */
    protected $name;

    public function getId()
    {
        return $this->id;
    }

    public function setId($id)
    {
        $this->id = (int)$id;
    }
    public function getName()
    {
        return $this->name;
    }
    public function setName($name)
    {
        $this->name = (string) $name;
    }
}

but that gives me the following error:

Fatal error: require_once(): Cannot redeclare class me\entity\category in App/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/AnnotationDriver.php on line 197

I figured this was because the Category.php gets required twice. So i got a temporary fix by adding a "guard" in the Category.php

 if (defined('CATEGORY_GUARD')) return;
define('CATEGORY_GUARD', true);

This works but of course is not how it's supposed to be done. Anybody who has any idea why this entity gets required twice?

  • i have not used the Category entity anywhere
  • the first time it is required as: category.php (normal c) the second time as Category.php (capital C)
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器