KnpPaginatorBundle: An exception has been thrown during the rendering of a template ("Notice: Array to string conversion").
i am having an issue with the template rendering, and I am pulling my hair out over it. Please could you help.
When I add pagination I get the error:
An exception has been thrown during the rendering of a template (“Notice: Array to string conversion”).
The offending template is:
vendor/knplabs/knp-paginator-bundle/templates/Pagination/twitter_bootstrap_v4_pagination.html.twig
However I have tried other templates.
My controller:
$currentTenant = $tenantContext->getCurrentTenant();
$em = $this->getDoctrine()->getManager();
$qualificationLevelRepository = $em->getRepository(QualificationLevel::class);
$qualificationLevelsQuery = $qualificationLevelRepository->createQueryBuilder('q')
->andWhere('q.tenant = :val')
->setParameter('val', $currentTenant)
->orderBy('q.id', 'ASC')
->getQuery();
$qualificationLevels = $paginator->paginate(
// Doctrine Query, not results
$qualificationLevelsQuery,
// Define the page parameter
$request->query->getInt('page', 1),
// Items per page
5
);
return $this->render('administration/qualification_level/manage-qualification-levels.html.twig', [
'controller_name' => 'QualificationLevelController',
'tenant' => $currentTenant,
'qualificationLevels' => $qualificationLevels
]);
My Page:
<table class="table table-hover">
...
<tbody>
{% if qualificationLevels|length == 0 %}
<tr>
<td colspan="9">{{ 'There are no campuses set up yet.'|trans }}</td>
</tr>
{% endif %}
{% for qualificationLevel in qualificationLevels %}
<tr data-href="#" data-id="{{ qualificationLevel.id }}" class="load-cqualificationLevel-edit-popup">
<th scope="row">{{ qualificationLevel.id }}</th>
<td>{{ qualificationLevel.name }}</td>
<td>{{ qualificationLevel.description }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="navigation">
{{ knp_pagination_render(qualificationLevels) }}
</div>
My YAML:
knp_paginator:
page_range: 5 # number of links showed in the pagination menu (e.g: you have 10 pages, a page_range of 3, on the 5th page you'll see links to page 4, 5, 6)
default_options:
page_name: page # page query parameter name
sort_field_name: sort # sort field query parameter name
sort_direction_name: direction # sort direction query parameter name
distinct: true # ensure distinct results, useful when ORM queries are using GROUP BY statements
filter_field_name: filterField # filter field query parameter name
filter_value_name: filterValue # filter value query parameter name
template:
pagination: '@KnpPaginator/Pagination/twitter_bootstrap_v4_pagination.html.twig'
#pagination: '@KnpPaginator/Pagination/sliding.html.twig' # sliding pagination controls template
#sortable: '@KnpPaginator/Pagination/sortable_link.html.twig' # sort link template
#filtration: '@KnpPaginator/Pagination/filtration.html.twig' # filters template
It was installed with the following command: composer require knplabs/knp-paginator-bundle
Please can you help.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15
found the problem, there was an exception in one of my tenant classes which was not bubbling up or showing until I installed the profiler.
I fixed that, the profiler now works as does the paginator.
Thanks for your help, I will close this issue.