Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.1k views
in Technique[技术] by (71.8m points)

php - 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;
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...