【发布时间】:2019-06-22 12:51:42
【问题描述】:
前提条件
ext:news 列表视图插件位于 www.domain.com/news [ID 9] 页面和 www.domain.com/article [ID 39] 页面上的详细视图。
按照官方示例(docs.typo3.org)
我尝试了功能描述的"Extbase Plugin Enhancer" example,但这导致了一些问题:
- 页面浏览器链接到第 2 页有一个 cHash:news/list/2?cHash=123456789
- 从第 2 页到第 1 页的页面浏览器链接有很多获取参数:news?tx_news_pi1%5Baction%5D=list&tx_news_pi1%5Bcontroller%5D=News&cHash=123456789。如果没有 routeEnhancer,它只会是没有任何获取参数的“新闻”。
- 详细视图的链接有一个 cHash:article/blog/9?cHash=52e8a4b7c6318cfe0273e7eab374e9ae
- 网址包含不需要的段(“列表”+“博客”)
- acticle url 不包含新闻标题
其中一些问题的一个原因可能是分页器未在其链接中指定控制器: news?tx_news_pi1[@widget_0][currentPage]=2&cHash=123456789
我的方法,已经解决了上述问题
我将其拆分为两个单独的 routeEnhancers(Extbase + Plugin),删除了“defaultController”、“defaults”、“requirements”这些段并添加了“aspects”:
routeEnhancers:
NewsDetail:
type: Extbase
limitToPages: [39]
extension: News
plugin: Pi1
routes:
- { routePath: '/{news_title}', _controller: 'News::detail', _arguments: {'news_title': 'news'} }
aspects:
news_title:
type: PersistedAliasMapper
tableName: 'tx_news_domain_model_news'
routeFieldName: 'path_segment'
NewsList:
type: Plugin
limitToPages: [9]
routePath: '/{@widget_0/currentPage}'
namespace: 'tx_news_pi1'
aspects:
'@widget_0/currentPage':
type: StaticRangeMapper
start: '1'
end: '1000'
我对这种方法的担忧:
- 我不确定添加一些“默认值”和“要求”是否具有优势(性能或安全性),以及将其拆分为两个单独的路由增强器是否真的是一种好习惯。
- 它将列表视图页面的数量限制为最多 1000 个(我承认这是很多)。较高的值将导致错误:范围大于 1000 项。
- 如果新闻标题中有斜线 / (例如“月报 2018/07") 自动生成的 path_segment 也将包含 斜线(“monthly-report-2018/07”),这导致以下内容 列表视图中的错误:路由的参数“tx_news_pi1__news” “tx_news_pi1_0”必须匹配“[^/]++”(给出“monthly-report-2018/07”) 生成相应的 URL。
【问题讨论】:
标签: typo3 extbase tx-news typo3-extensions typo3-9.x