【发布时间】:2012-10-21 08:44:40
【问题描述】:
我制作了一个基本的捆绑包。在我的包中,我的 Doctrine 实体之一需要进行扩展,所以我需要知道如何加载我的包的用户创建的实体。
我看到其他捆绑包在做一些事情,例如:
my_bundle:
product_class: Acme\MyBundle\Entity\Product
然后做类似的事情:
$product = $this->container->get( 'my_bundle.product_manager' ); // somehow uses the yaml value for my_bundle.product_class
$product->setName( 'test' );
$product->save( );
似乎这些包正在以某种方式将 YAML 转换为可用的学说实体。他们是如何做到这一点的以及最好的方法?
【问题讨论】:
-
为什么不使用控制器中的类:"use Acme\MyBundle\Entity\Product" 这样你就可以创建它:"$product = new Product()"