php – Symfony3错误命名空间不包含任何映射实体

我尝试在Symfony 3.0.1中生成getter和setter

当我运行命令

php bin/console doctrine:generate:entities VendorName/MyBundle/EntityName

我有错误

Namespace "VendorName\MyBundle\EntityName" does not contain any mapped entities.

哪里出错了?

编辑-1:首先生成具有YAML格式的实体

编辑-2:我尝试为供应商包生成getter和setter

另外我尝试使用命令php bin / console doctrine:generate:entities VendorNameMyBundle:EntityName并有另一个错误:

Can't find base path for "VendorName\MyBundle\Entity\EntityName" (path: "/home/site/vendor/vendorname/mybundle/Entity", destination: "/home/site/vendor/vendorname/mybundle/Entity").  

最佳答案 正如 John Pancoast在他的 answer中指出一个不同的问题:

Doctrine does not support PSR-4 when doing anything with code generation. It has to do with how they map class namespaces to filesystem paths and how PSR-4 allows class/namespace paths that don’t directly map to the filesystem.

07002

澄清解决错误消息所需的确切内容;您必须编辑bundle的composer.json文件,并更改bundle的文件夹结构.

在composer.json中将psr-4更改为psr-0:

"autoload": {
    "psr-4": { "Acme\\Bundle\\AwesomeBundle\\": "" }
},

至:

"autoload": {
    "psr-0": { "Acme\\Bundle\\AwesomeBundle\\": "" }
},

更改bundle的文件夹结构:

vendor
 +--acme
     +--awesome-bundle
         |--Controller
         |--Entity

至:

vendor
 +--acme
     +--awesome-bundle
         +--Acme
             +--Bundle
                 +--AwesomeBundle
                     |--Controller
                     |--Entity

以下命令将不再抛出异常:

bin/console doctrine:generate:entities AwesomeBundle
点赞