简体   繁体   中英

RealURL: Optional segments in FixedPostVars

I'm using RealURL in my Typo3 4.5.16 project for speaking URLs of a certain page. For this, I'm using a lookup-table that matches a certain number of IDs to their URL counterparts.

Eg
http://www.example.com/path/to/catalog/chapter1/section1/group1/prod-123/
would map to page "catalog" with parameters mapped for chapter , section , group , and product , resp. Note that only the LAST of those parameters is relevant and has a real mapping, the others are only there for a "pretty" path.

Now my problem: not every product has all levels of preceeding path segments. For example, another product might have a URL like this:
http://www.example.com/path/to/catalog/chapter1/section4/prod-789/

The database would look like this:

Id  | seg0      | seg1      | seg2      | seg3      | dummy0    | dummy1    | dummy2    | MapId
----|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------
1   | chapter1  | section1  | group1    | prod-123  | 1         | 1         | 1         | 123
2   | chapter1  | section4  |           | prod-789  | 1         | 4         | 0         | 789

You see that the mapping to a segment name is just empty.

RealURL would however use an empty string as the group, and produce
chapter1/section4//prod-789

Is there a way to suppress such an empty mapping? Will decoding pass the segment to the next parameter (like noMatch => bypass for value maps)

If not, can multiple path segments be mapped at once using lookup table? (ie mapping the whole path to the real ID)?

您可能要尝试使用realUrl提供的钩子, 请参阅本文

Well, I found a hacky workaround myself.

It uses userFunc tions, that basically mimic the behaviour of lookupTable. For every level there is one such function. It modifies the $params['pathParts'] array that is passed to the unser functions

Encoding:

  • For the "parent" levels, just map to the segment. This will return empty strings if not mapped.
  • For the mapped level, remove all empty elements at the end of the passed $params['pathParts'] array
  • => Removes empty parts

Decoding:

  • For the "parent" levels, check if there are more elements in $params['pathParts'] . If not, this is a "skipped" parent. Just append the current value to the $params['pathParts'] , which will be passed to the next level by RealURL
  • The mapped level eventually is called with the correct value. Just map

It works as long as the handling of userFunctions is not changed too much by RealURL...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM