我有两个api调用,我想在一个中实现它们。无论我尝试哪种方式,都会显示错误
变量“ playTicket”不存在。
我的呼叫首先创建一个表单,然后单击“添加”,我想在同一页面上填充该表单下方的表。
我的api调用..
public function playTicketsAddAction(Request $request, $id)
{
$form = $this->createFormBuilder()
->add('play', TextType::class, array('label' => 'Play', 'attr' => ['class' => 'form-control']))
->add('title', TextType::class, array('label' => 'Title', 'attr' => ['class' => 'form-control']))
->add('price', TextType::class, array('label' => 'Price', 'attr' => ['class' => 'form-control']))
->add('amount', TextType::class, array('label' => 'Amount', 'attr' => ['class' => 'form-control']))
->add('validFrom', DateType::class, array('label' => 'Valid From', 'attr' => ['class' => 'form-control']))
->add('validTo', DateType::class, array('label' => 'Valid To', 'attr' => ['class' => 'form-control']))
->add('save', SubmitType::class, array('label' => 'Add', 'attr' => ['class' => 'btn btn-primary pull-right action-save']))
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
$play = $data['play'];
$title = $data['title'];
$price = $data['price'];
$amount = $data['amount'];
$validFrom = $data['validFrom'];
$validTo = $data['validTo'];
$this->container->get('plays')->addNewPlayTicket($play, $title, $price, $amount, $validFrom, $validTo);
}
$this->addFlash('info', 'Ticket for this play was successfully <a href="/" class="alert-link">added</a>!');
return $this->render('@AdminTemplates/pages/manage-tickets.html.twig', array(
'form' => $form->createView(),
));
}
和
public function TicketsListAction()
{
$query = $this->getDoctrine()
->getRepository('AppBundle:playTickets')
->findAll();
$build['playTicket'] = $query;
return $this->render('@AdminTemplates/pages/seat-number-list.html.twig', $build);
}
这是我的树枝视图
<div class="card-body">
{{ form_start(form, {'method': 'POST'}) }}
<div class="row">
<div class="col-md-12">
<div class="form-group">
{{ form_row(form.play) }}
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
{{ form_row(form.title) }}
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
{{ form_row(form.price) }}
</div>
</div>
<div class="col-md-6">
<div class="form-group">
{{ form_row(form.amount) }}
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
{{ form_row(form.validFrom) }}
</div>
</div>
<div class="col-md-6">
<div class="form-group">
{{ form_row(form.validTo) }}
</div>
</div>
</div>
{{ form_end(form) }}
</div>
</div>
</div>
</div>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table">
<thead class=" text-primary">
<th>ID</th>
<th>Play Name</th>
<th>Title</th>
<th>Price</th>
<th>Amount</th>
<th>Valid From</th>
<th>Valid To</th>
<th>Actions</th>
</thead>
{% for p in playTicket %}
<tbody>
<tr>
<tr>
<td>{{ p.id }}</td>
<td>{{ p.playName }}</td>
<td>{{ p.theaterName }}</td>
<td>{{ p.validFrom|date("m/d/Y") }}</td>
<td>{{ p.validTo|date("m/d/Y") }}</td>
<td class="text-primary">{{ p.status }}</td>
<td class="td-actions text-left">
<a href="" rel="tooltip" title="Edit" class="btn btn-white btn-link btn-sm">
<i class="material-icons">edit</i>
</a>
<a href="" data-toggle="confirmation" data-message="Are you sure to delete this item?" rel="tooltip" title="Remove" class="btn btn-white btn-link btn-sm">
<i class="material-icons">delete</i>
</a>
</td>
</tr>
</tbody>
{% endfor %}
</table>
</div>
</div>
我希望这样做而不使用ajax或其他方法,因为我尚未掌握该部分。 :)