typo3 - TYPO3 9.5 LTS routeEnhancers for news with uid 使路径独一无二
问题描述
您好,我在 TYPO3 Slack 频道上发现以下内容是一个人正在使用的内容。这个片段yaml
存在于/config/my-websitename/config.yaml
...
routeEnhancers:
NewsList:
type: Extbase
limitToPages: [2,20,21,22,92]
extension: News
plugin: Pi1
routes:
- routePath: '/p{page}'
_controller: 'News::list'
_arguments: {'page': '@widget_0/currentPage'}
- routePath: '/{news_title}'
_controller: 'News::detail'
_arguments: {'news_title': 'news'}
defaultController: 'News::list'
defaults:
page: '0'
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'
问题
但我注意到,当我有多篇标题相同的文章时,没有唯一的 URL。
问题
如何将文章添加uid
到路径以使其独一无二,或者这是一个好主意?我发现它在文档中被忽略了,但不知道如何让它发挥作用来扩展我已经拥有的东西,或者如果有人可以给我一个更好的例子来说明如何获取新闻的唯一网址?
解决方案
答案
routeEnhancers:
NewsPlugin:
type: Extbase
extension: 'News'
plugin: 'Pi1'
routes:
- { routePath: '/{news_title}', _controller: 'News::detail', _arguments: {'news_title': 'news'} }
defaultController: 'News::list'
aspects:
news_title:
type: PersistedPatternMapper
tableName: 'tx_news_domain_model_news'
routeFieldPattern: '^(?P<path_segment>.+)-(?P<uid>\d+)$'
routeFieldResult: '{path_segment}-{uid}'
推荐阅读
- python - 并排排列和打印numpy数组值
- android - 有没有办法以编程方式从 com.android.filemanager 安装 apk
- linux - Ubuntu 18.04 上 Docker 的 Elasticsearch 文件描述符错误
- sql - 多值参数在 SSRS 报告中不起作用
- javascript - 来自动态输入文本JS的总和
- html - 内容安全策略问题
- php - 使用 PHP stream_context_create 读取远程二进制文件
- php - 无法调用作曲家命令
- java - ArrayLists and Vector comparison
- python - Why is my requests.Session() starting a new HTTP connection when used within a multiprocessing.Process?