Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7851763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:15:36+00:00 2026-06-02T19:15:36+00:00

Here you can find my n -th question on Symfony2. I’m working with a

  • 0

Here you can find my n-th question on Symfony2.

I’m working with a pagination bundle that uses the route name provided in the routing.yml file.
From my perspective, this approach is not flexible and lead to a dirty code, since if I change the name of the route, then I have to look at all the Twig templates or PHP files to update the route name. This is ok for small Web applications, but will provide such a bug for larger applications and also need an high burden for the developer.

So, I was wondering to pass a string variable x to the Pager object provided by the above mentioned bundle. The string x should be initialized within the controller and has to provide the desired route name as given in the routing.yml file.

Let me give an example. The routing file is the following:

//routing.yml
 AcmeTestBundle_listall:
pattern:  /test/page/{page}
defaults: { _controller: AcmeTestBundle:List:listall, page: 1 }
requirements:
    page:  \d+   

Then the related controller is:

//use something....
class ListController extends Controller
{

  public function exampleAction($page)
  {
    $array = range(1, 100);
    $adapter = new ArrayAdapter($array);
    $pager = new Pager($adapter, array('page' => $page, 'limit' => 25));

    return array('pager' => $pager);  
  }
}

Then, in the twig template, the $pager receives the route name that refer to the above bundle

{% if pager.isPaginable %}
   {{ paginate(pager, 'AcmeTestBundle_listall') }}
{% endif %}
{% for item in pager.getResults %}
   <p>{{ item }}</p>
{% endfor %}

Any idea of how to get the ‘AcmeTestBundle_listall’ string value at runtime just inside the controller?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:15:37+00:00Added an answer on June 2, 2026 at 7:15 pm

    You can use the app global variable that is available in twig to get the current route from the request.

    {% if pager.isPaginable %}
       {{ paginate(pager, app.request.get('_route') }}
    {% endif %}
    

    More about app here and here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this question is an extension of my previous question that you can find here:
Maybe is a often repeated question here, but i can't find anything similar with
I can't find anything anywhere(search engines, docs, here, etc) that shows how to create
Preamble I've searched to see if I can find this question anywhere on here
I've search through about 10 pages, can't find this question here. I'm trying to
I can't find any question similar to what I'm looking for, that is why
I'm a new Ruby/Rails guy. Here's one question puzzling me: Can we find the
you can find a similar question here PHP Post Request inside a POST Request
First time asking a question here. Usually I can find my answer without having
I've look at the questions on here but can't find an answer that specifically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.