我正在尝试在奏鸣曲中创建一个自定义页面,我基本上阅读了当前月份创建的特定表(行情)的记录。每个报价都涉及金钱,因此在表格的末尾我为当月的总计添加了一个额外的行。
现在,由于这是一个自定义模板,我希望能够将奏鸣曲的显示操作按钮放在每条引语上,但我找不到方法……有什么想法吗?谢谢!
我没有使用 Admin 类,因为我正在覆盖自定义 CRUDController 中的 listAction 方法,如您在此处看到的...
public function listAction()
{
if (false === $this->admin->isGranted('LIST')) {
throw new AccessDeniedException();
}
$datagrid = $this->admin->getDatagrid();
$formView = $datagrid->getForm()->createView();
// set the theme for the current Admin Form
$this->get('twig')->getExtension('form')->renderer->setTheme($formView, $this->admin->getFilterTheme());
$data = array();
$em = $this->getDoctrine()->getManager();
$request = $this->getRequest();
$form = $this->createFormBuilder(null, array('label' => 'Month: '))
->add('month', 'choice', array(
'choices' => $this->getMonths(),
'label' => false
))
->add('search', 'submit', array(
'attr' => array('class' => 'btn-small btn-info'),
))
->getForm();
$form->handleRequest($request);
if($request->isMethod('POST')){
$startDate = new \DateTime($form->get('month')->getData());
$endDate = new \DateTime($form->get('month')->getData());
$endDate->modify('last day of this month');
} else {
$endDate = new \DateTime('now');
$startDate = new \DateTime('now');
$startDate->modify('first day of this month');
}
$dql = 'SELECT q FROM AcmeQuoteBundle:Quote q WHERE q.date BETWEEN \' '
. $startDate->format('Y-m-d') . '\' AND \'' . $endDate->format('Y-m-d')
. '\' ORDER BY q.date DESC';
$query = $em->createQuery($dql);
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$query,
$this->get('request')->query->get('page', 1)/*page number*/,
50/*limit per page*/
);
$data['logrecords'] = $pagination;
return $this->render('AcmeQuoteBundle:Admin:quoteReport.html.twig',
array('data' => $data,
'action' => 'list',
'form' => $form->createView(),
'datagrid' => $datagrid
));
}
这是我正在使用的树枝:
{% block list_table %}
{% set logrecords = data.logrecords %}
{# total items count #}
<div class="count">
<h4>Total number of records founded: {{ logrecords.getTotalItemCount }} </h4>
</div>
<table class="table table-striped table-hover table-bordered ">
<thead class="info">
<tr >
<th>#</th>
<th>{{ knp_pagination_sortable(logrecords, 'Created at', 'q.date') }}</th>
<th>{{ knp_pagination_sortable(logrecords, 'Quote token', 'q.viewToken') }}</th>
<th>Business name</th>
<th>$AUD</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% set grandTotal = 0.0 %}
{% for quote in logrecords %}
{% set total = 0.0 %}
{% for item in quote.items %}
{% set total = (item.unit * item.rate) %}
{% endfor %}
{% set grandTotal = grandTotal + total %}
<tr>
<td>{{ loop.index }}</td>
<td>{{ quote.date | date('Y-m-d') }}</td>
<td>{{ quote.viewToken }}</td>
<td>{{ quote.request.business.name }}</td>
<td>{{ total }}</td>
<td>
<!-- THIS IS WHERE I WANT TO SHOW THE SHOW BUTTON -->
<a href="" role="button"><i class="icon-search"></i> SHOW</a>
</td>
</tr>
{% endfor %}
<tr>
<td colspan="3"></td>
<td>TOTAL (AUD): </td>
<td>{{ grandTotal }}</td>
<td></td>
</tr>
</tbody>
</table>
{# display navigation #}
<div class="navigation">
{{ knp_pagination_render(logrecords) }}
</div>
{% endblock list_table %}