我读这篇文章:Symfony2的 - 学说:架构:更新失败实体包(去耦)外
http://danielribeiro.org/yes-you-can-have-low-coupling-in-a-symfony-standard-edition-application/
笔者提到的,它可能有这种artitcture为项目:
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
现在的Symfony不能看到我的user.php的,如果我有添加任何额外的代码,使这个作品的作者并没有提到,现在我得到这个错误:
MappingException: The class 'Product\Entity\User' was not found in the chain configured namespaces OtherNameSpaces
UPDATE
所以我删除了我现有的代码。并没有这样的事情:
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查看文件夹里面的内容吗?
什么是你在user.php的命名空间? – Tib
'命名空间Product \ Entity' @Tib – trrrrrrm
@nifr答案就在它之上。我的文章,你第一次听到这种做法,并没有解释(有意)在内部如何做。 –