我正在使用 knp 分页器捆绑包,但出现此错误There is no such field [catalogId] in the given Query component, aliased by [u]
。如果我单击标题,排序工作正常,但如果我单击 catalogid,它会显示一个错误。CatalogId 是 ManytoOne 关系。我已经用谷歌搜索了答案,但似乎没有什么对我有用。你能告诉我如何解决这个问题吗? ?
这是我的控制器:
public function indexAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$postData = $request->query->all();
$form = $this->createForm(new SkuInventoryType(), new SkuInventory());
$form->handleRequest($request);
if($postData){
$repo = $this->getDoctrine()->getRepository('RetailMappingCatalogBundle:SkuInventory');
//dump($repo);die;
$skuQuery = $repo->createQueryBuilder('u')
->orderBy($postData['sort'],$postData['direction']);
}else{
$skuQuery = $em->getRepository('RetailMappingCatalogBundle:SkuInventory:u')->findAll();
}
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$skuQuery,
$request->query->get('page', 1),
15
);
if ($form->isSubmitted() && $form->isValid())
{
$data = $form->getData();
$data->setCreatedBy($this->getUser());
$data->setUpdatedBy($this->getUser());
$em->persist($data);
$em->flush();
$alertMessage = $this->get('retail_mapping.alert_message');
$alertMessage->success('SKU Inventory Created');
return $this->redirect($this->generateUrl('sku_inventory'));
}
return $this->render('User/SkuInventory/index.html.twig',[
'form' => $form->createView(),
'pagination' => $pagination,
]);
}
这是我的观点:
<table class="table table-bordered table-striped">
<tr>
<th>Id</th>
<th{% if pagination.isSorted('u.title') %} class="sorted"{% endif %}>{{ knp_pagination_sortable(pagination, 'Title', 'u.title') }}</th>
<th{% if pagination.isSorted('u.catalogId') %} class="sorted"{% endif %}>{{ knp_pagination_sortable(pagination, 'SKU', 'u.catalogId') }}</th>
<th>Actions</th>
</tr>
{% for sku in pagination %}
<tr>
<td>{{ loop.index }}</td>
<td>{{ sku.title}}</td>
<td> {{sku.catalogId.title}}</td>
<td><a class="btn btn-primary" href="{{path('sku_inventory_edit',{'id': sku.id})}}">Edit</a>
<a class="btn btn-primary" href="{{path('sku_inventory_delete',{'id': sku.id})}}">Delete</a></td>
</tr>
{% endfor %}
</table>
<div class="navigation">
{{ knp_pagination_render(pagination) }}
</div>