我包括了用于新闻插件的RouteEnhancers,并且在新闻列表和新闻详细信息页面的预期范围内工作。现在,我尝试实现DateMenu存档,并且出现了一些问题。
我的config.yaml看起来像这样。
routeEnhancers:
PageTypeSuffix:
type: ForceAppendingSlash
NewsPlugin:
type: Extbase
extension: News
plugin: Pi1
routes:
- routePath: '/news/{page}'
_controller: 'News::list'
_arguments:
page: '@widget_0/currentPage'
- routePath: '/{news_title}'
_controller: 'News::detail'
_arguments:
news_title: news
- routePath: '/archiv/{year}/{month}'
_controller: 'News::archive'
defaultController: 'News::list'
defaults:
page: '0'
requirements:
page: \d+
aspects:
news_title:
type: PersistedAliasMapper
tableName: tx_news_domain_model_news
routeFieldName: path_segment
我的DateMenu.html看起来像这样:
<ul>
<f:for each="{data.single}" key="year" as="months">
<li>
<ul>
<f:for each="{months}" key="month" as="count">
<li>
<f:link.action pageUid="{listPid}" arguments="{overwriteDemand:{year: year, month: month}}">{year} {month}</f:link.action>
</li>
</f:for>
</ul>
</li>
</f:for>
</ul>
列表看起来不错,但是我不知道是否存在Urls缓存或其他错误。会像RealUrl一样再次出现一个概述,以便您可以查看所有缓存的Urls吗?
答案 0 :(得分:1)
是,URL似乎已被缓存。我需要在“维护”模块(在“管理工具”下)中刷新Typo3和PHP缓存:
但是,我认为您的routeEnhancers配置中存在错误。它们没有在CoreApiReference中得到很好的记录,但是更改日志中有很好的描述: https://docs.typo3.org/typo3cms/extensions/core/latest/Changelog/9.5/Feature-86365-RoutingEnhancersAndAspects.html
看看DateMenu生成的URL-可能像这样:
http://yoursite.com
/path/to/newspage/
?tx_news_pi1[controller]=News
&tx_news_pi1[overwriteDemand][year]=2018
&tx_news_pi1[overwriteDemand][month]=10
&cHash=361b6057014505217b6186a508418f6f
因此控制器不是“存档”,而是“列表”。您需要在config.yaml中进行更改。我也认为您需要为此路由配置参数:
routePath: '/archive/{year}/{month}'
_controller: 'News::list'
_arguments:
year: overwriteDemand/year
month: overwriteDemand/month
这应该转换/摆脱两个&tx_news_pi1 [overwriteDemand] 参数。
下一步,为了删除 cHash ,请查看config.yaml文件末尾的“ aspects:” 部分。您已经为“ news_title” 定义了一个-并且必须为新的“ year” 和“ month” 参数添加两个。在变更日志https://docs.typo3.org/typo3cms/extensions/core/latest/Changelog/9.5/Feature-86365-RoutingEnhancersAndAspects.html#staticvaluemapper
中有一个多语言/本地化的示例下面是我的整个config.yaml和DateMenu.html文件。我的设置是:
rootPageId: 1
base: /
baseVariants: { }
languages:
-
title: Deutsch
enabled: true
languageId: '0'
base: /
typo3Language: de
locale: de_CH
iso-639-1: de
navigationTitle: De
hreflang: de
direction: ''
flag: global
-
title: English
enabled: true
languageId: '1'
base: /en/
typo3Language: default
locale: en_US
iso-639-1: en
navigationTitle: En
hreflang: en-US
direction: ''
fallbackType: strict
flag: gb
errorHandling: { }
routes: { }
routeEnhancers:
NewsPlugin:
type: Extbase
limitToPages:
- 14
- 39
extension: News
plugin: Pi1
routes:
-
routePath: '/{news_title}'
_controller: 'News::detail'
_arguments:
news_title: news
-
routePath: '/{year}'
_controller: 'News::list'
_arguments:
year: overwriteDemand/year
defaultController: 'News::list'
defaults:
page: '0'
aspects:
news_title:
type: PersistedAliasMapper
tableName: tx_news_domain_model_news
routeFieldName: path_segment
year:
type: StaticRangeMapper
start: '2000'
end: '2200'
<div class="news-menu-view">
<ul>
<f:for each="{data.single}" key="year">
<li>
<f:link.action pageUid="{listPid}" arguments="{overwriteDemand:{year: year}}">{year}</f:link.action>
</li>
</f:for>
</ul>
</div>