Php Symfony2-原则:模式:更新失败,实体位于捆绑包之外(解耦)

Php Symfony2-原则:模式:更新失败,实体位于捆绑包之外(解耦),php,symfony,orm,doctrine-orm,mapping,Php,Symfony,Orm,Doctrine Orm,Mapping,我在读这篇文章: 作者提到,该项目有可能采用这种艺术形式: src/ └── Vendor/ └── Product/ └── Bundle └── BlogBundle/ └── ForumBundle/ └── SiteBundle/ └── Controller/ └── IndexController.php

我在读这篇文章:

作者提到,该项目有可能采用这种艺术形式:

src/
└── Vendor/
    └── Product/
        └── Bundle
            └── BlogBundle/
            └── ForumBundle/
            └── SiteBundle/
                └── Controller/
                    └── IndexController.php
                └── Resources/
                    └── views/
                        └── index.html.twig
                └── ProductSiteBundle.php
        └── Entity
            └── User.php
        └── Repository
            └── UserRepository.php
        └── Service
            └── UserPasswordRetrievalService.php
因此,我跟随这篇文章,最终得出如下结论:

src/
└── Product/
    └── Bundle
        └── SiteBundle/
            └── Controller/
                └── IndexController.php
            └── Resources/
                └── views/
                    └── index.html.twig
            └── ProductSiteBundle.php
    └── Entity
        └── User.php
src/
└── Product/
    └── Bundle
        └── SiteBundle/
            └── Controller/
                └── IndexController.php
            └── Resources/
                └── views/
                    └── index.html.twig
            └── ProductSiteBundle.php
    └── Entity
        └── User.php
现在Symfony看不到我的User.php作者没有提到我是否需要添加任何额外的代码来实现此功能,现在我遇到了以下错误:

MappingException: The class 'Product\Entity\User' was not found in the chain configured namespaces OtherNameSpaces
更新

所以我删除了我现有的代码。做了这样的事情:

src/
└── Product/
    └── Bundle
        └── SiteBundle/
            └── Controller/
                └── IndexController.php
            └── Resources/
                └── views/
                    └── index.html.twig
            └── ProductSiteBundle.php
    └── Entity
        └── User.php
src/
└── Product/
    └── Bundle
        └── SiteBundle/
            └── Controller/
                └── IndexController.php
            └── Resources/
                └── views/
                    └── index.html.twig
            └── ProductSiteBundle.php
    └── Entity
        └── User.php
User.php

namespace Product\Entity;

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

    public function __construct()
    {
        parent::__construct();

    }
}
然后

php app/console doctrine:schema:update --force //No Metadata Classes to process.
似乎Symfony根本不知道这个文件夹。有什么地方可以让symfony查看该文件夹吗?

Jakub Zalas的一篇文章介绍了如何映射位于捆绑包之外的实体

您需要手动添加条令查找映射信息的位置,如下所示

这使得映射信息也可用于
条令:schema:update
命令。不要忘记在配置更改后清除缓存

# app/config/config.php
doctrine:
    orm:
        # ...
        mappings:
            Acme:
                type: annotation
                is_bundle: false
                dir: %kernel.root_dir%/../src/Acme/Entity
                prefix: Acme\Entity
                alias: Acme
您现在可以这样访问存储库(因为别名定义):


User.php中的名称空间是什么?
namespace-Product\Entity
@Tib@nifr答案就在上面。我的文章,您第一次听说这种做法的地方,并没有(故意)解释您是如何在内部进行的。@DanielRibeiro喜欢您的文章-我们绝对应该提高对良好应用程序设计的认识。继续努力!:)@丹尼尔里贝罗确实是一篇伟大的文章!谢谢你检查我的问题