2

In a controller, I define a form which lets the user do some changes on some fields:

$page['community'] is an entity with president, vicepresident, secretary and administrator properties, among others. Each one associated to a Pro\UserBundle\Entity\User entity (id):

    $form = $this->createFormBuilder($page['community'])
        ->add('president', 'entity', array(
            'label' => "Presidente",
            'class' => 'Pro\UserBundle\Entity\User',
            'property' => 'fullName',
            'choices' => $page['community']->getOwners()
        ))
        ->add('vicepresident', 'entity', array(
            'label' => "Vicepresidente",
            'class' => 'Pro\UserBundle\Entity\User',
            'property' => 'fullName',
            'choices' => $page['community']->getOwners(),
            'required' => false
        ))
        ->add('secretary', 'entity', array(
            'label' => "Secretario",
            'class' => 'Pro\UserBundle\Entity\User',
            'property' => 'fullName',
            'choices' => $page['community']->getOwners(),
            'required' => false
        ))
        ->add('administrator', 'entity', array(
            'label' => "Administrador",
            'class' => 'Pro\UserBundle\Entity\User',
            'property' => 'fullName',
            'choices' => $page['community']->getMembers(),
            'required' => false
        ))
        ->getForm();

    if ($this->getRequest()->isMethod('post')) {
        if ($form->bind($this->getRequest())->isValid()) {
            $this->getEntityManager()->flush();
            ...

This works right. But now I want to fire some events depending on the changed properties. E.g. I want to fire an event when the administrator property has changed.

I can get the whole new values, but I don't know which of them have changed. I could get those values before the flush and then compare each one with the new values, but maybe there is a simpler way to achieve it. Any idea?

Manolo
  • 24,020
  • 20
  • 85
  • 130
  • 1
    have a look at http://stackoverflow.com/questions/9057558/is-there-a-built-in-way-to-get-all-of-the-changed-updated-fields-in-a-doctrine-2 – Rooneyl Apr 15 '14 at 13:41
  • you need to do some logic depending on the user? or every time the admin user change ? in other words you need to know the previus value of the field ? – metalvarez Apr 15 '14 at 13:42
  • @metalvarez - No. Just the new value. – Manolo Apr 15 '14 at 13:45
  • @Rooneyl - Whow! I'm getting the old and new value of each changed property as values inside an array. Thank you very much. – Manolo Apr 15 '14 at 13:57
  • I dont know what you are looking for.. check this may help http://stackoverflow.com/questions/5221633/select-submit-only-changed-form-fields-with-jquery – Dilip Rajkumar Mar 30 '15 at 06:38

0 Answers0