gpt4 book ai didi

TYPO3 路由和方面 - 从 URL 中删除 cHash

转载 作者:行者123 更新时间:2023-12-04 17:33:30 25 4
gpt4 key购买 nike

对于 TYPO3 9.5,我尝试使用自定义方面来管理我的扩展程序中的 URL。 url 生成有效,但附加了一个 cHash。首先,我不想要这个 cHash(这里没有必要),其次,cHash 破坏了链接的功能(我得到一个 cHash-comparsion-error)。

我读了https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/9.5/Feature-86365-RoutingEnhancersAndAspects.html#impact另一次关于动态参数和cHash。要删除 cHash,我应该为所有占位符添加方面。我只有一个占位符和一个方面,但存在 cHash。

原始网址看起来像这样:
&tx_psoabilling_pi1[action]=showband&tx_psoabilling_pi1[controller]=Band&tx_psoabilling_pi1[band]=564&cHash=jkg24hwek8ufhqwezweklfzh

它被渲染成这样:
2019-thisisaname?cHash=o28z3hkwejghweuhzlk

这里是 config.yaml 的部分:

 PsoabillingPlugin:
type: Extbase
extension: Psoabilling
plugin: Pi1
routes:
- routePath: '/{yearandbandname}'
_controller: 'Band::showband'
_arguments:
yearandbandname: band
defaultController: 'Band::listyear'
aspects:
yearandbandname:
type: BandAndYearMapper

BandAndYearMapper.php

<?php

namespace EnzephaloN\ThemePsoa\Routing\Aspect;

use TYPO3\CMS\Core\Routing\Aspect\PersistedMappableAspectInterface;
use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;

class BandAndYearMapper implements PersistedMappableAspectInterface{

use SiteLanguageAwareTrait;

/**
* @param string $value
* @return string|null
*/
public function generate(string $value): ?string{
if($uid=intval($value)){
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_psoabilling_domain_model_band');
$statement = $queryBuilder
->select('b.uid', 'b.name', 'y.year')
->from('tx_psoabilling_domain_model_band','b')
->leftJoin('b', 'tx_psoabilling_domain_model_year', 'y', 'b.year = y.uid')
->where(
$queryBuilder->expr()->eq('b.uid', $queryBuilder->createNamedParameter($uid))
)
->execute();
if($record = $statement->fetch()){
if(is_array($record)){
return $record['year']. "-" .str_replace(" ","-",trim(strtolower($record['name'])));
}
}
}
return null;
}

/**
* @param string $value
* @return string|null
*/
public function resolve(string $value): ?string{
$year = substr($value, 0, 4);
$name = str_replace("-", " ", substr($value, 5));
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_psoabilling_domain_model_band');
$statement = $queryBuilder
->select('b.uid')
->from('tx_psoabilling_domain_model_band','b')
->leftJoin('b', 'tx_psoabilling_domain_model_year', 'y', 'b.year = y.uid')
->where(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->eq('y.year', $queryBuilder->createNamedParameter($year)),
$queryBuilder->expr()->orX(
$queryBuilder->expr()->like('b.name', $queryBuilder->createNamedParameter($name)),
$queryBuilder->expr()->like('b.name', $queryBuilder->createNamedParameter(substr($value, 5))), // if there was a - inside the bandname
$queryBuilder->expr()->like('b.name', $queryBuilder->createNamedParameter(substr($value, 5, strpos($name, " ")-1).'%')) // just find by beginning
)
)
)
->execute();
if($record = $statement->fetch()){
return (string)$record['uid'];
}
return null;
}
}

如何删除cHash??

最佳答案

如 Susi 所写,切换到 StaticMappableAspectInterface 是解决方案。类(class)现在开始于:

<?php

namespace EnzephaloN\ThemePsoa\Routing\Aspect;

use TYPO3\CMS\Core\Routing\Aspect\StaticMappableAspectInterface;
use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;

class BandAndYearMapper implements StaticMappableAspectInterface{

关于TYPO3 路由和方面 - 从 URL 中删除 cHash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57674403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com