Question

Does anybody know a way of configuring DBAL/Doctrine2 in a Symfony2 (symfony-reloaded) yml config file to execute a "set names" query? This question has been asked in other places, but I could not find a correct answer.

http://fossplanet.com/f6/%5Bsymfony-users%5D-symfony2-sandbox-database-collation-49626/

If there is no such config option, how can I implement this using PHP? Or better: Where is the right place in a Symfony2 project to do this?

Was it helpful?

Solution

That is not possible yet. I am working on allowing this already, will be possible soonish.

OTHER TIPS

Ok, just for anybody else who might run into this problem. This is what I did:

I ended up subclassing Symfony\Bundle\FrameworkBundle\Controller\Controller and introduced the method getEntityManager:

public function getEntityManager()
{
    $em = $this->get('doctrine.orm.entity_manager');
    static $utf8_set = false;
    if (!$utf8_set) {
        $em->getEventManager()->addEventSubscriber(new MysqlSessionInit('utf8','utf8_unicode_ci'));
        $utf8_set = true;
    }
    return $em;
}

So everytime I am want to access the EntityManager or a repository in my controllers (which of course now subclass DoctrineController) I call

$this->getEntityManager()

resp.

$this->getEntityManager()->getRepository('What\Ever\Entity\I\Am\Looking\For')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top