我在对表格进行排序时遇到了该错误:
request.CRITICAL:未捕获的PHP异常 Symfony \ Component \ Debug \ Exception \ FatalErrorException:“错误:对成员函数hasField()的调用为null”,位于/ vendor / knplabs / knp-components / src / Knp / Component / Pager / Event / Subscriber / Sortable / Doctrine / ORM / Query / OrderByWalker.php第57行{“ exception”:“ [对象] Symfony \ Component \ Debug \ Exception \ FatalErrorException(代码:0): 错误:在/vendor/knplabs/knp-components/src/Knp/Component/Pager/Event/Subscriber/Sortable/Doctrine/ORM/Query/OrderByWalker.php:57)上调用成员函数hasField()为null []
第一页按预期显示,单击页面索引也可以,但是按任何条件(sector.id/sector.name/sector.client.name)订购时都会出现问题。调试过程中我意识到未设置$meta['metadata']
,因此hasField($field)
崩溃了。
控制器:
public function indexAction() {
$em = $this->getDoctrine()->getManager();
$dql = "SELECT s as sector, COUNT(e.station) AS count_stations
FROM SectorsBundle:Sector s
LEFT JOIN s.stations e
GROUP BY e.sector";
$query = $em->createQuery($dql);
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$query,
$this->get('request')->query->getInt('page', 1),
$this->container->getParameter('num_elements')
);
return $this->render('SectorsBundle:Backend:indexSector.html.twig', array('pagination' => $pagination));
}
前端树枝文件:
<table class="tablesorter" cellspacing="0">
<thead>
<tr>
<th>{{ knp_pagination_sortable(pagination, ('sector.id' | trans), 'sector.id')|raw }}</th>
<th>{{ knp_pagination_sortable(pagination, ('sector.nom' | trans), 'sector.name')|raw }}</th>
<th>{{ knp_pagination_sortable(pagination, ('sector.client' | trans), 'sector.client.name')|raw }}</th>
<th>{{'sector.estacions' | trans}}</th>
</th>
</tr>
</thead>
<tbody>
{% for entity in pagination %}
<tr>
<td>{{ entity.sector.id }}</td>
<td>
<a href="{{ path('backend_sector_edit', { 'id': entity.sector.id }) }}">{{ entity.sector.name }}</a>
</td>
<td>
<a href="{{ path('backend_sector_edit', { 'id': entity.sector.id }) }}">{{ entity.sector.client.nom }}</a>
</td>
<td>
<a href="{{ path('backend_station_by_sector', { 'id': entity.sector.id }) }}">{{'sector.see.stations'| trans({'%count%': entity.count_stations})}}</a>
<ul>
<li>
<a href="{{ path('backend_sector_edit', { 'id': entity.sector.id }) }}" />
</li>
<li>
<a href="{{ path('backend_sector_delete', { 'id': entity.sector.id }) }}" />
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
参数:
knp_paginator.template.pagination: BackendBundle:Pagination:sliding.html.twig
knp_paginator.template.sortable: BackendBundle:Pagination:sortable_link.html.twig
knp_paginator.default_options.page_name: page
knp_paginator.default_options.sort_field_name: sort
knp_paginator.default_options.sort_direction_name: direction
knp_paginator.default_options.distinct: true
knp_paginator.default_options.filter_field_name: filterField
knp_paginator.default_options.filter_value_name: filterValue
composer.json
:
{
"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-0": { "": "src/" }
},
"classmap": [
"app/AppKernel.php", "app/AppCache.php"],
"require": {
"symfony/symfony": " 2.8.41",
"doctrine/orm": " >=2.2.3,<2.5-dev",
"doctrine/doctrine-bundle": "^1.10",
"twig/extensions": "^1.5",
"symfony/assetic-bundle": "^2.8",
"symfony/swiftmailer-bundle": "2.2.*",
"symfony/monolog-bundle": "^3.3",
"sensio/distribution-bundle": "^5.0",
"sensio/framework-extra-bundle": "3.*",
"sensio/generator-bundle": "^3.1",
"jms/security-extra-bundle": "^1.6",
"jms/di-extra-bundle": "^1.9",
"phpoffice/phpexcel": "^1.8",
"jms/metadata": "^1.7",
"friendsofsymfony/jsrouting-bundle": "^2.3",
"stfalcon/tinymce-bundle": "2.*",
"knplabs/knp-paginator-bundle": "^2.8",
"symfony/security-guard": "2.*",
"jms/serializer-bundle": "^2.4",
"nelmio/api-doc-bundle": "^2.13",
"aws/aws-sdk-php-symfony": "^2.0"
},
"scripts": {
"post-install-cmd": [
"Sensio\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
],
"post-update-cmd": [
"Sensio\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
]
},
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web",
"branch-alias": {
"dev-master": "2.1-dev"
}
}
}
关于什么地方有什么问题的建议/提示?