#router #typo3-extensions #realurl #typo3-9.x
#маршрутизатор #typo3-расширения #realurl #typo3-9.x
Вопрос:
Мой URL-адрес
backPid=5amp;tx_viextendednews_newsblog[action]=showamp;tx_viextendednews_newsblog[controller]=Extendednewsamp;tx_viextendednews_newsblog[extendednews]=1
и я хочу сделать это
/news-detail/newstitle/?backpid=5
Я написал в своем файле ext_local.conf $ GLOBALS [‘TYPO3_CONF_VARS’][‘SYS’][‘routing’][‘CustomPlugin’] = VrisiniInfotechLLP ViExtendednews Routing CustomEnhancer::class;
И мой customenhancer
class CustomEnhancer extends AbstractEnhancer implements RoutingEnhancerInterface, ResultingInterface
{
/**
* @var array
*/
protected $configuration;
/**
* @var string
*/
protected $namespace;
public function __construct(array $configuration)
{
$this->configuration = $configuration;
$this->namespace = $this->configuration['namespace'] ?? '';
}
}
Мой путь config.yaml
/siteroot/typo3conf/sites/foldername/config.yaml
routeEnhancers:
NewsPlugin:
type: Extbase
limitToPages: [13]
extension: Extendednews
plugin: newsblog
routes:
- { routePath: '/detail/{news_title}', _controller: 'Extendednews::show', _arguments: {'news_title': 'news'} }
defaultController: 'Extendednews::show'
aspects:
news_title:
type: PersistedAliasMapper
tableName: 'tx_news_domain_model_news'
routeFieldName: 'path_segment'
routeValuePrefix: '/'
Как я могу понять, что этот файл работает внутри?
Теперь мой вопрос в том, что я должен написать в этом файле, чтобы я мог получить желаемый URL?
Ответ №1:
Я использую следующий код для собственного аспекта маршрутизации. Используйте DebuggerUtility::var_dump($value), чтобы посмотреть, что происходит в этом классе Aspect:
<?php
namespace VENDORMyExtensionRoutingAspect;
use TYPO3CMSCoreRoutingAspectStaticMappableAspectInterface;
use TYPO3CMSCoreSiteSiteLanguageAwareTrait;
use TYPO3CMSExtbaseUtilityDebuggerUtility;
class IdentifierValueMapper implements StaticMappableAspectInterface
{
use SiteLanguageAwareTrait;
/**
* {@inheritdoc}
*/
public function generate(string $value): ?string
{
return $value !== false ? (string)$value : null;
}
/**
* {@inheritdoc}
*/
public function resolve(string $value): ?string
{
return isset($value) ? (string)$value : null;
}
}
config.yaml
defaults:
identifierPlaceholder: ''
requirements:
identifierPlaceholder: '^[a-zA-Z0-9]{32}$'
aspects:
identifierPlaceholder:
type: IdentifierValueMapper
localconf.php
// Custom Routing Aspects Mapper
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['aspects']['IdentifierValueMapper'] = VENDORMyExtensionRoutingAspectIdentifierValueMapper::class;
Комментарии:
1. каков путь к вашему config.yaml?
2. путь к нему /typo3conf/sites/my-site-configuration/config.yaml docs.typo3.org/typo3cms/extensions/core/Changelog/9.2 /…