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 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流