0

TYPO3 9 Routing - the parameter gets overwritten by the defaults - 1 year and 8 months later we are trying to update to TYPO3 10 and after that to TYPO3 11. As you can see, the site-configuration worked für typo3 9 perfectly, but now it won't anymore.

routeEnhancers:
  Werbemittelshop:
    type: Extbase
    extension: Mwwerbemittelshop
    plugin: Mwwerbemittelshop
    routes:
      -
        routePath: '/{categoryname}/{categoryname2}/{categoryname3}'
        _controller: 'MwWsCategories::category'
        _arguments:
          categoryname: mwWsCategory
          categoryname2: mwWsCategory2
          categoryname3: mwWsCategory3
      -
        routePath: '/{productname}'
        _controller: 'MwWsCategories::product'
        _arguments:
          productname: mwWsProduct
    defaults:
      categoryname2: ''
      categoryname3: ''
    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
      categoryname3:
        type: PersistedAliasMapper
        tableName: tx_mwwerbemittelshop_domain_model_mwwscategories
        routeFieldName: slug
      productname:
        type: PersistedAliasMapper
        tableName: tx_mwwerbemittelshop_domain_model_mwwsproducts
        routeFieldName: slug

The "productname" works exactly as expected. It is a readable url like example.de/test123 and it uses the right action of the controller.

"categoryname2" and "categoryname3" are the problems. If I open example.de/category1/ it works but if I add a second or a third parameter my parameters are empty (example.de/category1/category2) and I don't understand it.

/**
     * action category
     *
     * @param \MwWerbemittelshop\Mwwerbemittelshop\Domain\Model\MwWsCategories $mwWsCategory
     * @param \MwWerbemittelshop\Mwwerbemittelshop\Domain\Model\MwWsCategories $mwWsCategory2
     * @param \MwWerbemittelshop\Mwwerbemittelshop\Domain\Model\MwWsCategories $mwWsCategory3
     * @return void
     */
    public function categoryAction(
        \MwWerbemittelshop\Mwwerbemittelshop\Domain\Model\MwWsCategories $mwWsCategory = null, 
        \MwWerbemittelshop\Mwwerbemittelshop\Domain\Model\MwWsCategories $mwWsCategory2 = null, 
        \MwWerbemittelshop\Mwwerbemittelshop\Domain\Model\MwWsCategories $mwWsCategory3 = null
    )
    {
        var_dump($this->request->getArguments());
        var_dump($mwWsCategory);
        exit;

Can somebody of you find my mistake? I tried so many versions of it and nothing worked. If you have questions or want some more code, just ask for it.

Thanks in advance.

Markenwirt
  • 31
  • 4
  • If you have set only `categoryname`, the URL end like '/category'. That's how you have defined the URL for your 'MwWsCategories::product'-path. But the given categoryname won't match the aspect `productname` and so you are ending up in the default-case: `defaultController: 'MwWsCategories::category'`- without any parameter. – Julian Hofmann Dec 13 '21 at 18:44
  • Thank you, but the funny thing is: categoryname alone and productname alone works fine. I don't know why, I had the same idea, but it works. Only if I combine categoryname with categoryname2, for example: example.com/category1/subcategory1 That combination won't work... – Markenwirt Dec 13 '21 at 18:56
  • Just a try: have you tried to change the order? So first try would be productname and after that the categories... – Julian Hofmann Dec 13 '21 at 19:00
  • Not a bad idea, I tried it, but it didn't change the results. example.com/product works example.com/category works example.com/category/subcategory doesn't work But I tried something new. I removed unter defaults "categoryname2" and now example.com/category/subcategory works but obviously example.com/category doesn't work anymore. Does that help in any way? – Markenwirt Dec 13 '21 at 21:17
  • And I managed to get an error message now: " Page Not Found The page did not exist or was inaccessible. Reason: The requested page does not exist" Our own Error-Handling before blocked that. – Markenwirt Dec 13 '21 at 21:27

1 Answers1

0

I can't say why, but it's working if you define each case as own route:

  • one category
  • two categories
  • three categories
  • productsname

...and a default-case without any given parameters (or defaults!):

routeEnhancers:
  Werbemittelshop:
    type: Extbase
    extension: Mwwerbemittelshop
    plugin: Mwwerbemittelshop
    routes:
      -
        routePath: '/{productname}'
        _controller: 'MwWsCategories::product'
        _arguments:
          productname: mwWsProduct
      -
        routePath: '/{categoryname}'
        _controller: 'MwWsCategories::category'
        _arguments:
          categoryname: mwWsCategory
      -
        routePath: '/{categoryname}/{categoryname2}'
        _controller: 'MwWsCategories::category'
        _arguments:
          categoryname: mwWsCategory
          categoryname2: mwWsCategory2
      -
        routePath: '/{categoryname}/{categoryname2}/{categoryname3}'
        _controller: 'MwWsCategories::category'
        _arguments:
          categoryname: mwWsCategory
          categoryname2: mwWsCategory2
          categoryname3: mwWsCategory3
    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
      categoryname3:
        type: PersistedAliasMapper
        tableName: tx_mwwerbemittelshop_domain_model_mwwscategories
        routeFieldName: slug
      productname:
        type: PersistedAliasMapper
        tableName: tx_mwwerbemittelshop_domain_model_mwwsproducts
        routeFieldName: slug
Julian Hofmann
  • 2,081
  • 1
  • 8
  • 16
  • I had to downgrade the system again, so that I can work on the rest of my todos. It will take me some days to try that, but I definitely will try it and give you my feedback. Thank you already! – Markenwirt Dec 15 '21 at 20:27