1

我做了一个基本的捆绑包。在我的包中,我的 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 转换为可用的学说实体。他们是如何做到这一点的以及最好的方法?

4

1 回答 1

0

通过使用 Symfony 文档中的服务工厂解决了这个问题。我将用户的参数传递给工厂,它作为存储库工作得很好。

于 2012-11-01T13:29:36.603 回答