typo3typo3-9.xsymfony-routing

TYPO3 9 Routing - the parameter gets overwritten by the defaults


I'm trying to create a URL-structure like /maincategory/subcategory/ and this works, it looks good but with my code it loses the parameter "mwWsCategory2" and replaces it with the value under "defaults". In this example the Parameter "mwWsCategory2" will be empty in the extbase-controller but the url looks nice and correct.

I tried to remove "defaults" than I get the correct parameter and the url looks fine, but "mwWsCategory2" is optional, so /maincategory/ won't work - but I need that option.

So I also tried keeping the "defaults"-thing, but removing "categoryname2" under "aspects". Than it looks like /maincategory/2/ BUT I get the parameter. So it must be a combination between defaults and PersistedAliasMapper - I think. Maybe. I hope someone smarter than me has an answer. :)

routeEnhancers:
  Werbemittelshop:
    type: Extbase
    extension: Mwwerbemittelshop
    plugin: Mwwerbemittelshop
    routes:
      - routePath: '/{categoryname}/{categoryname2}'
        _controller: 'MwWsCategories::category'
        _arguments:
          categoryname: 'mwWsCategory'
          categoryname2: 'mwWsCategory2'
    defaults:
      categoryname2: ''
    defaultController: 'MwWsCategories::category'
    aspects:
      categoryname:
        type: PersistedAliasMapper
        tableName: tx_mwwerbemittelshop_domain_model_mwwscategories
        routeFieldName: slug
      categoryname2:
        type: PersistedAliasMapper
        tableName: tx_mwwerbemittelshop_domain_model_mwwscategories
        routeFieldName: slug

Solution

  • Try this:

    routeEnhancers:
      Werbemittelshop:
        type: Extbase
        extension: Mwwerbemittelshop
        plugin: Mwwerbemittelshop
        routes:
          - routePath: '/{categoryname}/{categoryname2}'
            _controller: 'MwWsCategories::category'
            _arguments:
              categoryname: mwWsCategory
              categoryname2: mwWsCategory2
        defaults:
          categoryname2: ''
        defaultController: 'MwWsCategories::category'
        aspects:
          mwWsCategory:
            type: PersistedAliasMapper
            tableName: tx_mwwerbemittelshop_domain_model_mwwscategories
            routeFieldName: slug
          mwWsCategory2:
            type: PersistedAliasMapper
            tableName: tx_mwwerbemittelshop_domain_model_mwwscategories
            routeFieldName: slug
    

    Under "_arguements" you are mapping routePath placeholders to an variable/aspect.

    categoryname => mwWsCategory

    But defining aspects using the placeholder name. Just use the mapped aspects/variablename, so the definition could be mapped in the chain.