我想在 bundle 中提供自定义(原则 orm)列类型,但我不知道如何注册它们:
Type::addType('my_col', 'MyColType');
$em->getConnection()->getDatabasePlatform()
->registerDoctrineTypeMapping('my_col', 'my_col');
MyBundleClass::boot() 看起来是个好地方,但在 boot() 内部,我无法访问容器。
谢谢。
最佳答案
您可以使用 Bundle 类的属性 container
来检索正确的实体管理器(通常是 doctrine.orm.default_entity_manager
)
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Doctrine\ORM\EntityManager;
class AcmeMyBundle extends Bundle
{
/**
* {@inheritdoc}
*/
public function boot()
{
/* @var EntityManager $em */
$em = $this->container->get('doctrine.orm.default_entity_manager');
$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping(...);
}
关于php - bundle 如何为 Doctrine ORM 提供新的列类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25444503/