Project

General

Profile

Multi Variables Mapping Path

Added by Alex Tumovsky 30 days ago

Hello

Please advise how to better organize page routing (check inside the slot internalPathChanged) based on the principle of parsing a url with several parameters in the middle of the request.

For example: site.com/gallery/{1}/photo/{2}
Where: {1}, {2}, etc. are unknown transmitted parameters (both integer and text).

I managed to achieve this using the hierarchical pages method (internalPathMatches, internalPathNextPart), but the code looks very bad and I believe it can be done better.
maybe I don't fully understand how to do this according to the principle of hierarchy...

Has anyone encountered an optimal solution? Can you suggest a sensible solution for such page routing?
Maybe you can use something similar to the routing mechanism from oatpp (https://oatpp.io/docs/components/api-controller/#path-variables-mapping)

Thanks in advance


Replies (1)

RE: Multi Variables Mapping Path - Added by Matthias Van Ceulebroeck 1 day ago

Hello Alex,

I apologize for the belated reply. In this case, I would approach it with WMenu, where WMenu::setInternalPathEnabled() will be of great help to you. You can create a WMenu and call setInternalPathEnabled("gallery"). That will let the menu know it should match an incoming path /gallery/{1}/photo/{2} (omitting the origin). It will then look at the next part of the path /{1}/photo/{2}.

Depending on whether the set of possible values of {1} or {2} is small or large, you may want to add them to the menu eagerly/lazily, or not at all beforehand. In the latter case, you may need to do some customization of WMenu::internalPathChanged().

I believe that with this approach as your basis, you should be able to write clean code that encapsulates, and decides on, a single level.

If you have any further questions, feel free to respond.

Best,
Matthias

    (1-1/1)