我们有一个Typo3 9服务器,上面运行着许多网站。我们还提供了新闻插件,以方便添加博客文章。
使用Typo3 9,旧的RealURL系统已经过时,而倾向于内置系统。这适用于普通页面,但不适用于新闻文章。
我们已经实现了以下YAML Confic文件,该文件基于新闻插件提供的示例以及许多其他堆栈溢出帖子。问题是,虽然我们可以确认配置已加载,但会收到404错误:
404 Page not found!
Reason: The requested page does not exist
Current URL: /blog/2020-january/
然后,我们开始逐行深入检查代码,以了解发生了什么问题。我们确实设法渲染了/blog/2020-january/
页面,但是它没有内容。各个博客页面都无法解析。
是否应该寻找其他配置来启用此功能?我们有另一个Typo3员工来解决问题,但没有成功。
rootPageId: 156
base: 'https://example.site'
baseVariants: { }
languages:
-
title: English
enabled: true
languageId: '0'
base: /
typo3Language: default
locale: en_AU
iso-639-1: en
navigationTitle: ''
hreflang: ''
direction: ''
flag: au
errorHandling: { }
routes: { }
routeEnhancers:
PageTypeSuffix:
type: PageType
default: '/'
index: '/'
map:
'/': 0
NewsPlugin:
type: Extbase
extension: News
plugin: Pi1
limitToPages:
- 187
- 201
routes:
# Detail view:
- routePath: '/{news_title}'
_controller: 'News::detail'
_arguments: {'news_title': 'news'}
# Categories:
- routePath: '/{category}'
_controller: 'News::list'
_arguments: {'category': 'overwriteDemand/categories'}
# Tags:
- routePath: '/{tag_name}'
_controller: 'News::list'
_arguments: {'tag_name': 'overwriteDemand/tags'}
# Pagination:
- routePath: '/{page}'
_controller: 'News::list'
_arguments: {'page': '@widget_0/currentPage'}
# Archive:
- routePath: '/{localized_archive}/{year}/{month}'
_controller: 'News::archive'
# Date:
- routePath: '/{year}-{month}'
_controller: 'News::list'
_arguments:
year: overwriteDemand/year
month: overwriteDemand/month
defaultController: 'News::list'
defaults:
page: '0'
year: ''
month: ''
requirements:
page: '\d+'
news_title: '^[a-zA-Z0-9].*$'
aspects:
page:
type: StaticRangeMapper
start: '1'
end: '100'
news_title:
type: PersistedPatternMapper
tableName: tx_news_domain_model_news
routeFieldPattern: '^(?P<path_segment>.+)$'
routeFieldResult: '{path_segment}'
category:
type: PersistedAliasMapper
tableName: 'sys_category'
routeFieldName: 'title'
tag_name:
type: PersistedAliasMapper
tableName: 'tx_news_domain_model_tag'
routeFieldName: 'title'
localized_archive:
type: LocaleModifier
default: 'archive'
routeFieldName: 'title'
localeMap:
- languageId: 'de_.*'
value: 'archiv'
- languageId: 'fr_.*'
value: 'archives'
year:
type: StaticRangeMapper
start: '1970'
end: '2099'
month:
type: StaticValueMapper
map:
january: '01'
february: '02'
march: '03'
april: '04'
may: '05'
june: '06'
july: '07'
august: '08'
september: '09'
october: 10
november: 11
december: 12
答案 0 :(得分:0)
Please check your code see below code of news_title
routeEnhancers:新闻:类型:Extbase扩展:新闻插件:Pi1路线:-routePath:'/ {news-title}'_controller:'News :: detail'_arguments:news-title:新闻方面:news-title:类型:PersistedAliasMapper tableName:tx_news_domain_model_news routeFieldName:path_segment
从path_segment删除花括号,如上或在文档中删除花括号谢谢
答案 1 :(得分:0)
经过大量的努力,我们取得了成功。
首先,最终的工作配置:
routeEnhancers:
NewsPlugin:
type: Extbase
extension: News
plugin: Pi1
limitToPages:
- 201
- 187
routes:
-
routePath: '/{news_title}'
_controller: 'News::detail'
_arguments:
news_title: news
-
routePath: '/{category}'
_controller: 'News::list'
_arguments:
category: overwriteDemand/categories
-
routePath: '/{tag_name}'
_controller: 'News::list'
_arguments:
tag_name: overwriteDemand/tags
-
routePath: '/page-{page}'
_controller: 'News::list'
_arguments:
page: '@widget_0/currentPage'
-
routePath: '/{year}/{month}'
_controller: 'News::list'
_arguments:
year: overwriteDemand/year
month: overwriteDemand/month
defaultController: 'News::list'
# defaults:
# page: '0'
# year: ''
# month: ''
requirements:
page: \d+
# news_title: '^[a-zA-Z0-9].*$'
aspects:
page:
type: StaticRangeMapper
start: '1'
end: '100'
news_title:
type: PersistedAliasMapper
tableName: tx_news_domain_model_news
routeFieldName: path_segment
category:
type: PersistedAliasMapper
tableName: sys_category
routeFieldName: title
tag_name:
type: PersistedAliasMapper
tableName: tx_news_domain_model_tag
routeFieldName: title
year:
type: StaticRangeMapper
start: '1970'
end: '2099'
month:
type: StaticRangeMapper
start: '01'
end: '12'
#month:
# type: StaticValueMapper
# map:
# january: '01'
# february: '02'
# march: '03'
# april: '04'
# may: '05'
# june: '06'
# july: '07'
# august: '08'
# september: '09'
# october: 10
# november: 11
# december: 12
重要的事情:
我们从9.5.15升级到9.5.18。尚不清楚是否需要这样做。
在站点包中,默认的TypoScript模板包括link.skipControllerAndAction = 1
。需要删除它以在列表视图中显示文章的友好URL。 (请参见How to properly set url-routing for tx-news in TYPO3 9.5.5?)