Extending Sonata User Bundle and adding new fields [closed]

1. Create a new bundle Something like AcmeUserBundle. Create it and register it as you do normally. 2. Create a new User entity Then create a User and Group entity which extends Sonata\UserBundle\Entity\BaseUser and Sonata\UserBundle\Entity\BaseGroup. You should also add the configuration for the primary key, for instance: /** * @ORM\Entity * @ORM\Table(name=”fos_user”) */ class User … Read more

How can I use DATE() in Doctrine 2 DQL?

In addition to the accepted answer there are a tonne of pre-built custom functions available at https://github.com/beberlei/DoctrineExtensions . These can be then registered in your config like doctrine: orm: dql: string_functions: DATE: DoctrineExtensions\Query\Mysql\Date and can then be used in your DQL (as in your query) like DATE(jobs.endDate) AS endDate

FOSUserBundle : Redirect the user after register with EventListener

To accomplish what you want, you should use FOSUserEvents::REGISTRATION_CONFIRM instead of FOSUserEvents::REGISTRATION_CONFIRMED. You then have to rewrite rewrite your class RegistrationConfirmedListener like: class RegistrationConfirmListener implements EventSubscriberInterface { private $router; public function __construct(UrlGeneratorInterface $router) { $this->router = $router; } /** * {@inheritDoc} */ public static function getSubscribedEvents() { return array( FOSUserEvents::REGISTRATION_CONFIRM => ‘onRegistrationConfirm’ ); } public … Read more

Symfony: How do I refresh the authenticated user from the database?

Try this: $em = $this->getDoctrine()->getManager(); $loggedInUser = $this->get(‘security.context’)->getToken()->getUser(); $loggedInUser->addRole(‘ROLE_XYZ’); $em->persist($loggedInUser); $em->flush(); $token = new \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken( $loggedInUser, null, ‘main’, $loggedInUser->getRoles() ); $this->container->get(‘security.context’)->setToken($token);

Query on a many-to-many relationship using Doctrine with Symfony2

You can write a join DQL query as below $em = $this->getContainer()->get(‘doctrine’)->getManager(); $repository = $em->getRepository(‘YourNamespaceYourBundle:User’); $query = $repository->createQueryBuilder(‘u’) ->innerJoin(‘u.groups’, ‘g’) ->where(‘g.id = :group_id’) ->setParameter(‘group_id’, 5) ->getQuery()->getResult(); Your mapping for groups property in User entity will handle join part itself you don’t have to mention the junction table in your DQL query