doubi6215 2015-07-28 19:37
浏览 29

ZF2应用程序中的原则2:未找到实体“没有要处理的元数据类”。

In a Zend Framework 2 Project, Doctrine 2 is not able to find my Entities and I am not sure why. To me everything looks correct, but the php ./vendor/bin/doctrine-module orm:schema-tool:create command to create the database based on the entities results in No Metadata Classes to process..

Of course I made sure first that all modules are loaded, so it's not that easy ;-) I also already did some research on that problem and it seems that most of the time, it's namespace related, but again, I don't see anything wrong there. I also generated the autoload files.

Are you able to spot anything wrong in these files, why is Doctrine not able to find the Entities? Could it be related to something else than an error in my files?

In module.config.php, Doctrine is configured like this:

'doctrine' => [
    'driver' => [
      'Catalog_entities' => [
        'class' =>'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
        'cache' => 'array',
        'paths' => [__DIR__ . '/../src/Catalog/Entity']
      ],
    ],

    'orm_default' => [
      'drivers' => [
        'Catalog\Entity' => 'Catalog_entities'
      ],
    ],
],

module.config.php has no namespace declaration since it's included into Module.php which has namespace Catalog; at the top.

The Entity at module/Catalog/src/Catalog/Entity/WorkEntity.php looks like this:

namespace Catalog\Entity;

use Doctrine\ORM\Mapping as ORM;

    /** @ORM\Entity */
    class Work {
        /**
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         * @ORM\Column(type="integer")
         */
        protected $id;

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

        public function setId($id) {
          $this->id = $id;
        }
}
  • 写回答

1条回答 默认 最新

  • droc60607 2015-07-29 07:46
    关注

    First fix @Crisp his comment. File names and class names should always correspond.

    If that doesn't solve it you could check if you module.config.php is loaded correctly in your Module.php like this:

    /**
     * @return array
     */
    public function getConfig()
    {
        return __DIR__ . '/../../config/module.config.php';
    }
    

    I would also suggest using the namespace constant so you can simply copy your configs to different modules without changing a thing and minimizing the risk of overwriting another config when you forget to change something. So like this:

    'driver' => [
        __NAMESPACE__ . '_driver' => [
            'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
            'cache' => 'array',
            'paths' => [__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity']
        ],
        'orm_default' => [
            'drivers' => [
                __NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
            ]
        ]
    ],
    
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值