An exception has been thrown during the rendering of a template ("Some mandatory parameters are missing ("format") to generate a URL for route "app_admininquirylist_index".") in Admin/Common/menu.html.twig at line 2.
<?php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\Form\Extension\Core\Type\SearchType;
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use AppBundle\Entity\Inquiry;
use League\Csv\Writer;
/**
* @Route("/admin/inquiry")
*/
class AdminInquiryListController extends Controller
{
/**
* @Route("/search.{format}",
* defaults={"_format": "html"},
* requirements={
* "_format": "html|csv",
* }
* )
*/
public function indexAction(Request $request, $_format)
{
$form = $this->createSearchForm();
$form->handleRequest($request);
$keyword = null;
if ($form->isValid()) {
$keyword = $form->get('search')->getData();
}
$em = $this->getDoctrine()->getManager();
$inquiryRepository = $em->getRepository('AppBundle:Inquiry');
$inquiryList = $inquiryRepository->findAllByKeyword($keyword);
if ($_format == 'csv') {
$response = new Response($this->createCsv($inquiryList));
$d = $response->headers->makeDisposition(
ResponseHeaderBug::DISPOSITION_ATTACHMENT,
'inquiry_list.csv'
);
$response->headers->set('Content-Disposition', $d);
return $response;
}
return $this->render('Admin/Inquiry/index.html.twig',
[
'form' => $form->createView(),
'inquiryList' => $inquiryList
]
);
}
public function createSearchForm()
{
return $this->createFormBuilder()
->add('search', SearchType::class)
->add('submit', ButtonType::class, [
'label' => '検索',
])
->getForm();
}
private function createCsv($inquiryList)
{
/** @var Writer $writer */
$writer = Writer::createFromString('','');
$writer->setNewLine("\r\n");
foreach ($inquiryList as $inquiry) {
/** @var Inquiry $inquiry */
$writer->insertOne([
$inquiry->getId(),
$inquiry->getName(),
$inquiry->getEmail()
]);
}
return (string)$writer;
}
}
{% extends "Admin/layout.html.twig" %}
{% block title %}お問い合わせ管理{% endblock %}
{% block body %}
<h2 class="sub-header">お問い合わせ管理</h2>
<div>
{{ form_start(form, {'attr': {'id':'searchForm', 'novalidate': 'novalidate'}}) }}
検索:{{ form_widget(form.search) }}
{{ form_widget(form.submit, {"attr": {"class":"btn btn-default searchButton"}}) }}
{{ form_end(form) }}
<a class="btn btn-default downloadButton">CSVダウンロード</a>
</div>
<table class="table table-striped">
<thread>
<tr>
<th>#</th>
<th>日時</th>
<th>名前</th>
<th>種別</th>
<th>操作</th>
</tr>
</thread>
<tbody>
{% for inquiry in inquiryList %}
<tr>
<td></td>
<td>{% if inquiry.type == 0 %}公演について{% else %}その他{% endif %}</td>
<td>
<a class="btn btn-default"
href="{{ path("app_admininquiryedit_input", {"id":
inquiry.id}) }}">詳細</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script type="text/javascript">
$('.downloadButton').click(function() {
$('#searchForm').attr('action', '{{ path(
"app_admininquirylist_index", {"_format":"csv"}) }}');
$('#searchForm').submit();
});
$('.searchButton').click(function() {
$('#searchForm').attr('action', '{{ path(
"app_admininquirylist_index", {"_format":"html"}) }}');
$('#searchForm').submit();
});
</script>
{% endblock %}