Access Custom Route Parameter


#1

How do I access a parameter defined in a custom route?
$request->get('id'); returns NULL


#2

Hi there,

you can do it like that:

/**
 * @param Request $request
 *
 * @Route("/blog/{id}")
 */
public function indexAction(
    Request $request,
)
{
    $id = $request->get('id');
}

or like that

/**
 * @param Request $request
 *
 * @Route("/blog/{id}")
 */
public function indexAction(
    Request $request,
    $id = ''
)
{
    
}

if if its a get parameter you can get the parameter by $request->get(‘id’);

dump your request and look if the parameter is in the object if its not something went wrong with your call.


#3

Hmm, I know I can do it using Symfony annotations, but I wanted to do it using the pimcore custom/static route system, which, from my current experience, it’s a little garbage (not much :smiley:).


#4

Hi,
should work as you described as long as the parameter is named ‘id’.

If you don’t like the static routes, you always can use the symfony routes. I would prefer them anyway :slight_smile:

BR
Christian


#5

Yeah, seems like that’s the only option for now. Thank you.