D
D
Denis2018-08-18 15:04:35
symfony
Denis, 2018-08-18 15:04:35

How to organize routing from a database in Symfony 4?

Unfortunately, I can’t find a normal example in the documentation, there is something similar to symfony.com/doc/current/routing/custom_route_loade...
but I feel this option suits me in part.
Let's say the situation is a directory site.
site.ru/{+d}/ - displays all products depending on the pagination
site.ru/{slug}/ - and this can display a category or product page depending on the slug (the problem is that each category or product table has the corresponding slug field - you can of course make one table and get the necessary slug by one-to-one connection, and then everything will be much easier)
i.e. the usual logic is redirected to the desired action controller, depending on what came in the parameter
you can of course cheat, and do all these checks in the Index controller and pull out the necessary logic through the service, or go the easy way (site.ru/category/{slug}/ and site.ru/product/{slug}/)
but you want where -to see how to make the current situation the most "correct" approach?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2018-08-18
@sidni

the problem is that each category or product table has a corresponding slug field
It is possible to make representation where there will be slug'i from all tables.
But the idea of ​​collecting all of them in one table is also not bad - it will allow you to control their uniqueness by means of the database.
and pull out the necessary logic through the service
Is there forwarding

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question