Get entityManager inside an Entity

As pointed out (again) by a commenter, an entity manager inside an entity is a code smell. For the OP’s specific situation where he wished to acquire the entity manager, with the least bother, a simple setter injection would be most reliable (contrary to my original example injecting via constructor). For anyone else ending up … Read more

Symfony 2 load different template depending on user agent properties

Ok, so I don’t have a full solution but a little more than where to look for one 🙂 You can specify loaders (services) for templating item in app/config/config.yml framework: esi: { enabled: true } #translator: { fallback: %locale% } secret: %secret% router: resource: “%kernel.root_dir%/config/routing.yml” strict_requirements: %kernel.debug% form: true csrf_protection: true validation: { enable_annotations: true … Read more

JMSSerializerBundle. no control over third party meta data

I bet xxx\xxx\Entity\User: refers to your own namespace and class. If it is, it is the wrong way to do. The rules must be applied to the class where the properties live. Given the property you exposed in your configuration, I guess you’re using FOSUserBundle. Therefore, you must apply your rules on FOS\UserBundle\Model\User. Then you … Read more

Combining Assetic Resources across inherited templates

You can actually do the following: In layout.html.twig (or whatever your layout is) {% block stylesheets %} {% stylesheets ‘your_assets_here’ %} <link rel=”stylesheet” href=”https://stackoverflow.com/questions/6958970/{{ asset_url }}” /> {% endstylesheets %} {% endblock %} And in any template that extends that layout: {% block stylesheets %} {{ parent() }} {% stylesheets ‘additional_assets_here’ %} <link rel=”stylesheet” href=”https://stackoverflow.com/questions/6958970/{{ … Read more

Remove / Replace the username field with email using FOSUserBundle in Symfony2 / Symfony3

A complete overview of what needs to be done Here is a complete overview of what needs to be done. I have listed the different sources found here and there at the end of this post. 1. Override setter in Acme\UserBundle\Entity\User public function setEmail($email) { $email = is_null($email) ? ” : $email; parent::setEmail($email); $this->setUsername($email); return … Read more