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

  • Home
  • SEARCH
  • 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 3879778
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:45:57+00:00 2026-05-19T22:45:57+00:00

Hey. I was going to make a current class for my menu component, that

  • 0

Hey.
I was going to make a “current” class for my menu component, that creates the menus. To find out the current class, it was suggested to use $this>getContext()->getRouting()->getCurrentRouteName();. To do this, I had to set up routes for all the menu-elements that was going to exist.

Lets say I have two elements so far, one for the frontpage, one for the customer. Whenever I am browsing the frontpage, matter what action and parameters, I would like the above code to return “frontpage”. Same goes for customer.

My rule for customer now, is the following:
routing.yml

customer:
  param: { module: customer }

I thought that setting up the url was not important, I have already specified the module to be customer. The menu element should have “current” class no matter the action used.

How I link:

if ($current == $name){
    echo link_to($name, $link, array("class" => "selected"));
}else {
    echo link_to($name, $link);
}

Links ($link) that now go to “customer/some_action” does not work, they show up as just “/”. So I thought to use url_for around the $link, that didn’t work either, same result.

There must be something wrong with my routing rules… Because when I enter lets say /customer/new manually, I can see the page. If I from the template write out $this>getContext()->getRouting()->getCurrentRouteName();, it says default. So my rule definitely does not work at all. I’ve tried other rules too, but haven’t got anyone working. The trick is to make one rule that works for anything under the module customer..

And yes, I clear my cache after changing each of my rules.

Thanks a lot.

EDIT:
I made the routing rules work, but not for all actions under the customer module. I have to make rules for each action. But, the links are still broken, they show “/”.

My new rules:

customer_index:
  url:   /:module
  param: { module: customer, action: index }

customer_new:
  url:   /:module/:action
  param: { module: customer, action: new }

None of these links works:
echo link_to("Customers", "@customer_index", array("module" => "customer"));

echo link_to("New customer", "@customer_new", array("module" => "customer"));

  • 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-05-19T22:45:57+00:00Added an answer on May 19, 2026 at 10:45 pm

    Yep, this is how I’ve done it a few times as well. You need separate routing rules to use getCurrentRouteName().

    The problem you have with the links is that you cannot pass the “module” parameter in this way. It’s not a valid parameter for the Symfony link_to() helper. Instead, you can pass it this way:

    link_to('Customers', '@customer_index?url_variable=something');
    
    customer_index:
      url:   /:url_variable
      param: { module: customer, action: index, url_variable: some_default_value }
    

    The default value is optional, but the link_to helper will throw an error if you don’t pass the variable and the route doesn’t have a default value for it.

    Also, just pointing this out as you’ve got it twice wrong in your code above:

    $this>getContext()->getRouting()->getCurrentRouteName();
    ...should be:
    $this->getContext()->getRouting()->getCurrentRouteName();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey there, I've got a block of HTML that I'm going to be using
Hey I am trying to make a page that inserts some strings into a
Hey, how can I make it so that there's basically just a semi transparent
Hey, I think I'm going about this the wrong way, but have tried many
hey all, throwing this one out there... hope it's a simple one. using the
Hey all, my Computational Science course this semester is entirely in Java. I was
Hey, my script seems to be getting this warning message whenever I run it.
Hey all, my first post :D Problem: I'm trying to make a template gallery,
Hey guys, I am writing an application that retrieves the Group Names and access
hey, i got an question about what is going on in the next code:

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.