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"));