How to properly set url-routing for tx-news in TYPO3 9.5.5?

谁说胖子不能爱 提交于 2021-01-05 10:35:31

问题


I use TYPO3 V9.5.5 with PHP V7.2.10. Also there is tx-news plugin installed. The site configuration is set and works. But if I add routeEnhancers for news detail it doesnt't show it in the url. It always looks like: http://p510984.mittwaldserver.info/aktuell/detail?tx_news_pi1%5Bnews%5D=5&cHash=c68f25c1ef4b5bd7320220373cfed332

I searched for solutions in stackoverflow and google. Also I read the manual of the news extension https://docs.typo3.org/typo3cms/extensions/news/stable/AdministratorManual/BestPractice/Routing/

Even TYPO3 and PHP cache flushing doesn't help.

At the moment I have following code:

routeEnhancers:
  NewsPlugin:
    type: Extbase
    limitToPages:
      - 17
    extension: News
    plugin: Pi1
    routes:
      - { routePath: '/{news_title}', _controller: 'News::detail', _arguments: {'news_title': 'news'} }
    defaultController: 'News::list'
    defaults:
      page: '0'
    aspects:
      news-title:
        type: PersistedAliasMapper
        tableName: tx_news_domain_model_news
        routeFieldName: path_segment

Does it need "defaultController and defaults: page: 0"?


回答1:


As Nitori already mentioned in the comment, you need to unify the spelling of news_title / news-title.

But this doesn't seem to be your only problem. Without the aspect, your URL should at least look like:

http://p510984.mittwaldserver.info/aktuell/detail/5&cHash=c68f25c1ef4b5bd7320220373cfed332

This means, the whole route is currently not applied to your detail page.

As you use limitToPages, please check if 17 is the UID of your detail page.


For the pagination widget, category plugins etc. you will need to add the related page UIDs to limitToPages, and of course extend your routes. The news documentation shows examples for these use cases.




回答2:


Thats my config that works fine for me, maybe this helps...

News:
type: Extbase
extension: News
plugin: Pi1
routes:
  - routePath: '/'
    _controller: 'News::list'
  - routePath: '/page-{page}'
    _controller: 'News::list'
    _arguments:
      page: '@widget_0/currentPage'
  - routePath: '/{news-title}'
    _controller: 'News::detail'
    _arguments:
      news-title: news
  - routePath: '/{category-name}'
    _controller: 'News::list'
    _arguments:
      category-name: overwriteDemand/categories
  - routePath: '/{category-name}/page-{page}'
    _controller: 'News::list'
    _arguments:
      category-name: overwriteDemand/categories
      page: '@widget_0/currentPage'
defaultController: 'News::list'
defaults:
  page: '0'
aspects:
  news-title:
    type: PersistedAliasMapper
    tableName: tx_news_domain_model_news
    routeFieldName: path_segment
  page:
    type: StaticRangeMapper
    start: '1'
    end: '100'
  category-name:
    type: PersistedAliasMapper
    tableName: sys_category
    routeFieldName: slug


来源:https://stackoverflow.com/questions/55743425/how-to-properly-set-url-routing-for-tx-news-in-typo3-9-5-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!