WhiteOctoberPagerfantaBundle icon indicating copy to clipboard operation
WhiteOctoberPagerfantaBundle copied to clipboard

Pagination inside an embedded Controller

Open amirkoklan opened this issue 7 years ago • 4 comments

Hi There,

I want to have pagination inside an embedded Controller in the template {{ render_esi(controller('DFMVapBundle:Embeded/Contract:listContracts')) }} but it is giving me this error only when there is more than 1 page to navigate to.

An exception has been thrown during the rendering of a template ("None of the chained routers were able to generate route: Route '' not found").

is there a way to do that?

amirkoklan avatar Mar 07 '18 00:03 amirkoklan

Thanks for getting in touch, @amirkoklan. ESI is not an area of Symfony we're particularly knowledgeable in, and I'm afraid we don't have the time for the in-depth investigation that this issue would require. Hopefully someone else in the community can help, or do post back yourself if you make any progress here, as it may well help others.

Sorry not to be more help, Sam

sampart avatar May 01 '18 12:05 sampart

this also happens for "normal" embedded controllers, so it is no ESI issue.

{{ render(controller('App\\Controller\\SearchController::indexAction')) }}
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "" as such route does not exist.").

c33s avatar Jun 27 '18 11:06 c33s

the problem lies in PagerfantaExtension.php twig extension. if no options are set, the current request, which is a subrequest, and not the master request is taken for building the links to the pages. a subrequest has no real route name and contains only something like this

pathInfo: "/_fragment"
requestUri: "/_fragment?_path=_format%3Dhtml%26_locale%3Dde%26_controller%3DApp%255CController%255CSearchController%253A%253AindexAction"
baseUrl: ""

v1

we can solve this problem by adding a flag like "useMasterRequest" and then call getMasterRequest() instead of getCurrentRequest

    private function getRequest()
    {
        if ($this->requestStack && $request = $this->requestStack->getCurrentRequest) {

v2

because i don't want to maintain a fork i build a workaround, instead of changing the code of the twig extension, i created a new twig extension which provides a function to expose the master request in twig and set all options in the twig template for the pager:

{{ pagerfanta(stamps_pager, 'twitter_bootstrap3', { routeName: request_master().get('_route'), routeParams: request_master().query.all }) }}

c33s avatar Jun 28 '18 19:06 c33s

Thanks for your investigations here, @c33s. Could v1 be achieved by creating an additional option for the extension which can be passed when rendering? If so, I'd gladly merge a PR with that change if you're able to make one.

sampart avatar Aug 21 '18 11:08 sampart