[英]How to create a dynamic string route enhancer in TYPO3 CMS 9.5 LTS?
I've created a simple aspect for my extension route enhancer like so:我为我的扩展路由增强器创建了一个简单的方面,如下所示:
routeEnhancers:
Trainee:
type: Extbase
extension: Dsinstitution
plugin: Dslisttrainees
routes:
- routePath: '/trainee/{trainee-identifier}'
_controller: 'Trainee::show'
_arguments:
trainee-identifier: trainee
defaultController: 'Trainee::list'
aspects:
trainee-identifier:
type: PersistedPatternMapper
tableName: 'tx_dsinstitution_domain_model_trainee'
routeFieldPattern: '^(?<lastname>.+)-(?<prename>.+)-(?<uid>\d+)$'
routeFieldResult: '{lastname}-{prename}-{uid}'
The problem is if there is someone with a very cryptic name which would destroy the expected url structure (eg with &
or /
in it).问题是,如果有人的名字非常神秘,这会破坏预期的 url 结构(例如,其中包含
&
或/
)。 For that the extension news
uses a path_segment
attribute instead of multiple fields.为此,扩展
news
使用path_segment
属性而不是多个字段。
For that I've extended my ext_tables.sql with that attribute.为此,我使用该属性扩展了我的 ext_tables.sql。 But how can I force the TCA to auto fill it with the sanitized structure of "
lastname
- prename
- uid
"?但是我怎样才能强制 TCA 用“
lastname
- prename
- uid
”的净化结构自动填充它? I don't understand the news
extension way.我不明白
news
扩展方式。
Answer: Don't!回答:不要!
In the documentation and according to recommendations from several developers you shouldn't use free text fields in the Persisted Pattern Mapper.在文档中并根据几位开发人员的建议,您不应在持久模式映射器中使用自由文本字段。 Instead you use a
slug
for that in your TCA.相反,您在 TCA 中使用了一个
slug
。
For more have a look in the documentation: https://docs.typo3.org/m/typo3/reference-tca/master/en-us/ColumnsConfig/Type/Slug.html更多信息请查看文档: https : //docs.typo3.org/m/typo3/reference-tca/master/en-us/ColumnsConfig/Type/Slug.html
Adding to your TCA of your model something like:添加到模型的 TCA 中,例如:
'urlslug' => [
'exclude' => true,
'label' => 'urlslug',
'config' => [
'type' => 'slug',
'generatorOptions' => [
'fields' => ['lastname', 'prename', 'uid'],
'fieldSeparator' => '-',
'prefixParentPageSlug' => true
],
'fallbackCharacter' => '-',
'eval' => 'uniqueInSite',
'default' => ''
]
]
Remember to add urlslug
to your Model and to the ext_tables.sql of your extension as well.请记住将
urlslug
添加到您的模型和扩展程序的 ext_tables.sql 中。 Also slugs will only be generated on new objects, only created with TCA (backend).此外,slug 只会在新对象上生成,仅使用 TCA(后端)创建。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.