简体   繁体   中英

How to hide arguments from URL with a custom mapper TYPO3 9.5?

Previously my URL without implementing a custom mapper looked like this: https:\mydomain.com?tx_myextension%5Baction%5D=boat-action&tx_myextension%5BboatId%5D=boat-id&tx_myextension%5BboatName%5D=boat-name&tx_myextension%5Bcontroller%5D=boat-controller&cHash=hash

After the implementation of a custom URL mapper by extending the custom aspects I've reached this solution: https:\mydomain.com/boat-name/boat-id

What I am trying to achieve is to hide the boat-id from the URL, the ID is not stored in a table and it is required from the pages to load the datas.

Html that generates the link

<f:link.action  
    class="call-to-action horizontal" 
    action=“boat-action” 
    controller=“boat-controller”
    arguments="{
        boatId: '{boat.id}',
        boatName: '{boat.urlName}'
    }" 
    pageUid="218"
>

config.yaml

routeEnhancers:
    BoatName:
      type: Extbase
      limitToPages:
        - 218
      extension: myextension
      plugin: Singleboat
      routes:
        - routePath: '/{boatName}/{boatId}'
          _controller: Boat::boat-controller
      aspects:
        boatId:
          type: BoatNameMapper
        boatName:
          type: BoatNameMapper

custom mapper class

class BoatNameMapper implements StaticMappableAspectInterface
{
    use SiteLanguageAwareTrait;

    /**
     * {@inheritdoc}
     */
    public function generate(string $value): ?string
    {
        return $value !== false ? (string)$value : null;
    }

    /**
     * {@inheritdoc}
     */
    public function resolve(string $value): ?string
    {
        return isset($value) ? (string)$value : null;
    }
}

If you want your boat-Id in the URL, don't put it in. (config.yaml)

and especially: make your controller independent of the boat-Id. Otherwise you need it in the URL.


maybe an acceptable solution is another coding of boat-name and boat-Id.

what about: - routePath: '/{boatName}-{boatId}

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