Skip to content

OrderByWalker.php on line 57 - there is no $meta['metadata'] #535

Open
@ArantecEnginheria

Description

@ArantecEnginheria

Hi!

I got that error when sorting the table:

request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalErrorException: "Error: Call to a member function hasField() on null" at /vendor/knplabs/knp-components/src/Knp/Component/Pager/Event/Subscriber/Sortable/Doctrine/ORM/Query/OrderByWalker.php line 57 {"exception":"[object] (Symfony\Component\Debug\Exception\FatalErrorException(code: 0): Error: Call to a member function hasField() on null at /vendor/knplabs/knp-components/src/Knp/Component/Pager/Event/Subscriber/Sortable/Doctrine/ORM/Query/OrderByWalker.php:57)"} []

The first page shows as expected, click on page index works too, but the problem comes when ordering by any criteria (sector.id/sector.name/sector.client.name). Debugging I realize that $meta['metadata'] is not set, and therefore hasField($field) crashes.

Controller:

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,
    ));
}

Frontend twig file:

<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>&nbsp;</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></td>
                    <td>
                        <ul>
                            <li>
                                <a href="{{ path('backend_sector_edit', { 'id': entity.sector.id }) }}"><input type="image" src="{{ asset('backend/images/icn_edit.png') }}" title="Edit"></a>
                            </li>
                            <li>
                                <a href="{{ path('backend_sector_delete', { 'id': entity.sector.id }) }}"><input type="image" class="JS-delete" src="{{ asset('backend/images/icn_trash.png') }}" title="Delete"></a>
                            </li>
                        </ul>
                    </td>
                </tr> 
            {% endfor %}
    </tbody> 
</table>

Parameters:

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  

Any suggestion/hint about whats wrong?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions