Skip to content

Instantly share code, notes, and snippets.

@leevigraham
Created November 23, 2011 04:38

Revisions

  1. leevigraham revised this gist Nov 23, 2011. 1 changed file with 19 additions and 0 deletions.
    19 changes: 19 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    <form
    action="{{ path('put_activity', {'id': activity.object.id }) }}"
    method="post"
    {{ form_enctype(activity.edit_activity_form) }}
    >
    <input type="hidden" name="_method" value="PUT" />
    <input type="hidden" name="_target_path" value="get_activities" />
    {{ form_errors(activity.edit_activity_form) }}
    {{ form_widget(activity.edit_activity_form._token) }}
    <div class="ft ft-textarea ft-description">
    <label>
    {{ form_label(create_activity_form.description) }}
    </label>
    {{ form_widget(create_activity_form.description) }}
    </div>
    <div class="actions">
    <button type="submit">Edit Activity</button>
    </div>
    </form>
  2. leevigraham created this gist Nov 23, 2011.
    29 changes: 29 additions & 0 deletions ActivityType
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    <?php

    namespace Newism\ActivityBundle\Form;

    use Symfony\Component\Form\AbstractType,
    Symfony\Component\Form\FormBuilder,
    Symfony\Component\Form\FormEvents,
    Symfony\Component\Form\Event\DataEvent;

    use Newism\ProjectBundle\Form\EventListener\AddTaskFieldSubscriber;

    class ActivityType extends AbstractType
    {
    public function buildForm(FormBuilder $builder, array $options)
    {
    $builder
    ->add('description')
    ->add('duration')
    ->add('timerStartedAt')
    ->add('startedAt')
    ->add('user')
    ;
    }

    public function getName()
    {
    return 'newism_activitybundle_activitytype';
    }
    }
    30 changes: 30 additions & 0 deletions putActivityAction
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    <?php
    /**
    * Updates an existing Activity entity.
    * @Route("/activity/{id}", name="put_activity")
    * @Method("put")
    */
    public function putActivityAction($id)
    {
    $em = $this->getDoctrine()->getEntityManager();
    $activity = $em->getRepository('Newism\ActivityBundle\Entity\Activity')->find($id);
    if (!$activity) {
    throw $this->createNotFoundException('Unable to find Activity entity.');
    }
    $activity = $em->getRepository('Newism\ActivityBundle\Entity\Activity')->find($id);
    $editForm = $this->createForm(new ActivityType(), $activity);
    $request = $this->getRequest();
    $editForm->bindRequest($request);


    if ($editForm->isValid()) {
    $em->persist($activity);
    $em->flush();
    }

    if(!$target_path = $this->getRequest()->request->get('_target_path')) {
    $target_path = "get_activities";
    }

    return $this->redirect($this->generateUrl($target_path, array('id' => $activity->getId())));
    }