Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Pagination inside an embedded Controller #186

Open
amirkoklan opened this issue Mar 7, 2018 · 4 comments
Open

Pagination inside an embedded Controller #186

amirkoklan opened this issue Mar 7, 2018 · 4 comments

Comments

@amirkoklan
Copy link

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?

@sampart sampart changed the title Pagination Pagination inside an embedded Controller May 1, 2018
@sampart
Copy link
Owner

sampart commented May 1, 2018

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

@c33s
Copy link

c33s commented Jun 27, 2018

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
Copy link

c33s commented Jun 28, 2018

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

@sampart
Copy link
Owner

sampart commented Aug 21, 2018

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants