如何在TYPO3版本9

时间:2019-03-18 07:10:22

标签: router typo3-extensions realurl typo3-9.x

我的网址是

backPid = 5&tx_viextendednews_newsblog%5Baction%5D = show&tx_viextendednews_newsblog%5Bcontroller%5D = Extendednews&tx_viextendednews_newsblog%5Bextendednews%5D = 1

我想做到

/ news-detail / newstitle /?backpid = 5

我在ext_local.conf文件中写了 $ GLOBALS ['TYPO3_CONF_VARS'] ['SYS'] ['routing'] ['CustomPlugin'] = \ VrisiniInfotechLLP \ ViExtendednews \ Routing \ CustomEnhancer :: class;

我的自定义增强器是

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: '/'

我如何理解此文件在内部工作? 现在我的问题是我应该在该文件中写些什么,以便获得所需的网址?

1 个答案:

答案 0 :(得分:0)

我将以下代码用于自己的路由方面。 使用DebuggerUtility :: var_dump($ value)来查看此Aspect类中发生的情况:

    <?php
    namespace VENDOR\MyExtension\Routing\Aspect;

    use TYPO3\CMS\Core\Routing\Aspect\StaticMappableAspectInterface;
    use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait;
    use TYPO3\CMS\Extbase\Utility\DebuggerUtility;

    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'] = \VENDOR\MyExtension\Routing\Aspect\IdentifierValueMapper::class;