PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 18, 2022

[FIXED] How can a bundle provide new column type to Doctrine ORM?

 October 18, 2022     doctrine-orm, php, symfony     No comments   

Issue

I would like to provide custom (doctrine orm) column type in a bundle, but I don't know how to register them:

Type::addType('my_col', 'MyColType');
$em->getConnection()->getDatabasePlatform()
   ->registerDoctrineTypeMapping('my_col', 'my_col');

MyBundleClass::boot() looks like a good place, but inside boot(), I can not access container.

Thank you.


Solution

You can use the property container of the Bundle class to retrieve the right entity manager (usually 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(...);
    }


Answered By - rolebi
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing