Richard Bridge
Richard Bridge

Reputation: 388

KNP Paginator doesnt use correct URL

I cant seem to find out why this is happening, so I'm asking here.

In my controller SearchAssetsController.php I am using an API to get a list of assets. I then turn that array of assets into Entities. After that I paginate them:

/**
 * @param int      $limit
 * @param int      $offset
 * @param \Symfony\Component\HttpFoundation\Request $request
 *
 * @Route("/asset-search/{offset<\d+>?0}/{limit<\d+>?24}", name="asset_search")
 *
 * @return Response
 */
public function searchAssets(Request $request, PaginatorInterface $paginator, int $offset, int $limit): Response
{ 

.....

/* @Var PaginatorInterface $paginatedSearchResults */

// Get Asset IDs from results
$assetIDs = array_column($jsonResponse->results, 'id');

// Hydrate asset array
$assets = $this->assetRepository->getAssetsFromIds($assetIDs);

// Set up pagination
$paginatedSearchResults = $paginator->paginate($assets, 1 + $offset, $limit);
$paginatedSearchResults->setTotalItemCount($jsonResponse->total);
$paginatedSearchResults->setCustomParameters([$filters]);
$totalResultCount = $paginatedSearchResults->getTotalItemCount();

This works fine, and when I render the paginator at the bottom of the page in my twig file:

<div class="row">
    <div class="col">
        <div class="navigation">
            {{ knp_pagination_render(paginatedSearchResults) }}
        </div>
    </div>
</div>

It renders and looks nice, however the URL for each page is this:

https://domain.local/asset-search?page=5

But the route for the controller is /asset-search/{page}/{limit}. I am guessing the KNP Paginator generates the URL based on the route, but this isn't happening for me. What am I doing wrong?

Upvotes: 1

Views: 86

Answers (0)

Related Questions