Good morning,
I'm struggling with building the router for a shop system. The following should work:
- / <- displays landing page
- /Food <- displays all articles in Food
- /Food/Beverages <- displays all articles in Food/Beverages
- /Food/Beverages/Tea <- displays all articles in Food/Beverages/Tea
- /Food/Beverages/Tea/seo-friendly-product-name <- displays the actual article
- /Food/Sweets/seo-friendly-product-name <- displays the actual article
- /Outdoor <- display all articles in Outdoor ...
The main categories (food, outdoor, ..) are hardcoded and can easily be matched with something like
$router->add('(Food|Outdoor|...)') [ ..
...
The articles all have one main category, and (theoretically) an infinite amount of sub categories (Beverages, Tea, Sweets, ...). And their SEO-friendly name of course.
So, in theory, I need a route that would match on something like "get the main category", then "get an undefined amount of subcategories" and then allow one more part as the SEO name of the article, and if the latter is not provided, route to category controller.
The sub categories themselves are defined in relation to the article, so I can't hardcode them. Is it possible to maybe retrieve the categories from the database and build the routes from that?
How can I make the router to do this?
Thank you.