symfony2 chained selectors

OK, I finally figured out how to do it properly: namespace Test\TestBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; use Doctrine\ORM\EntityRepository; use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\Event\DataEvent; use Test\TestBundle\Entity\Country; use Test\TestBundle\Entity\State; use Test\TestBundle\Entity\City; class CityType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder->add(‘name’); $factory = $builder->getFormFactory(); $refreshStates = function ($form, $country) use ($factory) { $form->add($factory->createNamed(‘entity’,’state’, null, array( … Read more

Symfony2 default locale in routing

If someone is interested in, I succeeded to put a prefix on my routing.yml without using other bundles. So now, thoses URLs work : Edit your app/config/routing.yml: ex_example: resource: “@ExExampleBundle/Resources/config/routing.yml” prefix: /{_locale} requirements: _locale: |fr|en # put a pipe “|” first Then, in you app/config/parameters.yml, you have to set up a … Read more

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