OrderByWalker.php в строке 57 - нет $ meta ['metadata'] - PullRequest
0 голосов
/ 19 февраля 2019

Я получил эту ошибку при сортировке таблицы:

request.CRITICAL: Uncaught PHP Exception Symfony \ Component \ Debug \ Exception \ FatalErrorException: "Ошибка: вызов функции-члена hasField () onнольDebug \ Exception \ FatalErrorException (код: 0): Ошибка: вызов функции-члена hasField () для null по адресу / vendor / knplabs / knp-components / src / Knp / Component / Pager / Event / Subscriber / Sortable / Doctrine / ORM/Query/OrderByWalker.php:57) "} []

Первая страница отображается, как и ожидалось, нажатие на индекс страницы также работает, но проблема возникает при заказе по любому критерию (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"
        }
    }
}

Любые предложения / подсказки о том, что не так?

...