D
D
Dmitry Kim2020-02-17 07:26:32
symfony
Dmitry Kim, 2020-02-17 07:26:32

How to set dependent parameters for routes in Symfony annotations?

Let's say we have the following urls:

  • example.com/products/
  • example.com/products/page/{page}

Moreover, example.com/products/ == example.com/products/page/1 .
Is it possible to specify in the annotations that /page/- is optional. Those. if there is no page number following it, just example.com/products/ should be used ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Bitko, 2020-02-18
@kimono

Specify page as {slug} too. And set its default value and required value to only page.

@Route("/products/{page}/{pageNum}", name="product_paged_index", defaults={"page":"page", "pageNum": "1"}, requirements={"page"="page", "pageNum"="\d+"})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question