私は作成関数を作成します。ID を変数に格納し、この ID を編集関数に渡します。このためのコードをいくつか書きますが、エラーが存在します。ここに私のコードがあります:
var InvoiceId;
$("form").submit(function(e) {
e.preventDefault();
var url = $(this).attr('action');
var data = $(this).serialize();
$.ajax({
type: "POST",
url: url,
data: data,
})
.success(function( result ) {
invoiceid=result.id;
$("#edit").click();
if(result.success) {
$('#result').css({'color':'black','background-color':'#8F8','display':'Block','width':'200px'});
$('#result').html('Invoices Record Inserted');
setTimeout(function(){
$('#result').hide();
},3000);
window.location.href = "{{ path('invoicepreview') }}";
}
});
this.reset();
});
$("#edit").click(function(){
= "{{ path('invoices_edit', {'id': invoiceid }) }}";
});
ここに私の作成機能があります:
if($request->isXmlHttpRequest()) {
$response = new Response();
$output = array('success' => true, 'title' => $entity->gettitle(), 'id' => $entity->getId(), 'notes' => $entity->getnotes(), 'accountid' => $entity->getaccountid(), 'clientid' => $entity->getClientID(), 'status' => $entity->getstatus(), 'totalamount' => $entity->getTotalAmount(), 'paidamount' => $entity->getPaidAmount(), 'balanceamount' => $entity->getBalanceAmount(), 'createdby' => $entity->getcreatedby(), 'updatedby' => $entity->getupdatedby(), 'createddatetime' => $entity->getcreateddatetime(), 'updateddatetime' => $entity->getupdateddatetime());
$response->headers->set('Content-Type', 'application/json');
$response->setContent(json_encode($output));
}
ここに私の編集機能があります:
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('InvoicesInvoicesBundle:Invoices')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Invoices entity.');
}
$editForm = $this->createForm(new InvoicesType(), $entity);
$deleteForm = $this->createDeleteForm($id);
return $this->render('InvoicesInvoicesBundle:Invoices:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
ここにエラーがあります:
Variable "invoiceid" does not exist in InvoicesInvoicesBundle:Invoices:new.html.twig at line 362