1

This is my route

personeelslid_personeelslid_detail:
pattern: /personeelslid/detail/{personeelId}
defaults: 
    _controller: PersoneelPersoneelslidBundle:Personeelslid:detail
    _menu_icon: fa-user

locatiebeheer_kind_detail:
pattern: /locatiebeheer/kind/detail/{kindId}
defaults: { _controller: PersoneelLocatiemanagerBundle:KindDetail:detail }

In my menuBuilder I loop through all routes and fetch for example _menu_icon:

$routeObject = $this->_router->getRouteCollection()->get($route);               

$menu_icon = $routeObject->getDefault('_menu_icon');

How can I fetch the variable name personeelId, kindId, etc.. I need te keys so I can set the routeParameter attributes.

1 Answer 1

2

You can add custom keys to defaults option if you want. Example:

personeelslid_personeelslid_detail:
path: /personeelslid/detail/{personeelId}
defaults: 
    _controller: PersoneelPersoneelslidBundle:Personeelslid:detail
    _menu_icon: fa-user
    my_custom_key: personeelId

and get it:

$myCustomKey = $routeObject->getDefault('my_custom_key');

IF you want to fetch the value of wildcard, you cant' do it like this way (by getRouteCollection), fetch it from Request object (e.g. $request->attributes->all())..

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I knew this option. Was hoping for a more elegant way. I will do this way then.
@Bart I haven't seen better option yet, only this way or php's explode function and regex with getRouteCollection :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.