ajax - symfony2 update entity out of modal -
almost whole night i'm trying update entity form in modal, doesn't work...
my twig template looks :
{% entity in entities %} <tr> <td class="text-center">{{ entity.id }}</td> <td class="text-center">{{ entity.cashbackdays }} tage</td> <td class="text-center">{{ entity.cashbackpercent }} %</td> <td class="text-center">{{ entity.nettodays }} tage</td> <td class="text-center"> <a data-toggle="modal" data-target="#editcashbackmodal" class="btn btn-xs btn-default" href="{{ path('cashback_edit', { 'id': entity.id }) }}"><i class="fa fa-edit"></i></a> </td> </tr> {% endfor %} </tbody> <div class="modal fade" id="editcashbackmodal" tabindex="-1" role="dialog" aria-labelledby="editcashbackmodallabel" aria-hidden="true"> </div>
the modal template looks like:
<div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="editcashbackmodallabel">skontoschlüssel bearbeiten</h4> </div> <div class="modal-body"> {{ form(edit_form) }} <ul class="record_actions"> <li> <a href="{{ path('cashback') }}"> list </a> </li> <li>{{ form(delete_form) }}</li> </ul> </div> <div class="modal-footer"> </div> </div> </div>
i think got problems variable in url don't know how fix it.
this part of controller:
public function editaction($id) { $em = $this->getdoctrine()->getmanager(); $entity = $em->getrepository('sulzerappbundle:cashback')->find($id); if (!$entity) { throw $this->createnotfoundexception('unable find cashback entity.'); } $editform = $this->createeditform($entity); $deleteform = $this->createdeleteform($id); return array( 'entity' => $entity, 'edit_form' => $editform->createview(), 'delete_form' => $deleteform->createview(), ); } /** * creates form edit cashback entity. * * @param cashback $entity entity * * @return \symfony\component\form\form form */ private function createeditform(cashback $entity) { $form = $this->createform(new cashbacktype(), $entity, array( 'action' => $this->generateurl('cashback_update', array('id' => $entity->getid())), 'method' => 'put', )); $form->add('submit', 'submit', array('label' => 'update')); return $form; }
the error modal doesn't open @ click on edit
you have add form submission:
protected $requeststack; public function __construct(requeststack $requeststack) { $this->requeststack = $requeststack; } public function editaction($id) { $em = $this->getdoctrine()->getmanager(); $entity = $em->getrepository('sulzerappbundle:cashback')->find($id); if (!$entity) { throw $this->createnotfoundexception('unable find cashback entity.'); $editform = $this->createeditform($entity); $deleteform = $this->createdeleteform($id); $editform->handlerequest($this->requeststack); if ($editform->issubmitted() && $editform->isvalid()) { /** @var cashback $cashback */ $cashback = $editform->getdata(); ... $em->persist($cashback); $em->flush(); } ... return array( 'entity' => $entity, 'edit_form' => $editform->createview(), 'delete_form' => $deleteform->createview(), ); }
read more forms , symfony 2.7 demo
Comments
Post a Comment