You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TYPO3 v12:如何通过typenum调用控制器动作及实现根路径RSS访问

TYPO3 v12 路由与Typenum问题解决

问题1:Typenum调用时articles返回NULL

核心原因是Typenum访问时页面上下文未关联到新闻页面,导致getArticles()无法获取数据。默认Typenum请求会继承当前访问页面的PID,若直接通过Typenum访问根页面,而文章数据关联在/news页面PID下,自然拿不到数据。

解决方案:

  • 硬编码文章存储PID:修改getArticles()方法,不依赖当前页面上下文,直接指定新闻数据所在的存储PID:
protected function getArticles()
{
    // 替换为你的新闻存储PID
    $storagePid = 123; 
    return $this->articleRepository->findByStoragePage($storagePid);
}
  • 路由绑定页面上下文:在路由配置中添加_pageUid参数,强制指定新闻页面的PID,确保请求上下文正确:
- routePath: '/rss.xml'
  _controller: 'Article::feed'
  _pageUid: 456 # 替换为你的/news页面PID

问题2:直接访问domain.com/rss.xml

需将路由规则配置在站点级别的routes.yaml(而非扩展内部路由文件),让路由属于站点根路径。

配置步骤:

  1. 打开站点配置目录下的config/sites/[你的站点名]/routes.yaml
  2. 添加以下路由规则(根据你的扩展类型选择):
    • 若使用Extbase插件:
    routeEnhancers:
      ArticleFeedEnhancer:
        type: Extbase
        extension: 你的扩展名称
        plugin: 你的插件名称
        routes:
          - routePath: '/rss.xml'
            _controller: 'Article::feed'
            _pageUid: 456 # 指定新闻页面PID
        defaultController: 'Article::feed'
    
    • 若无需插件关联,用Simple类型简化配置:
    routeEnhancers:
      RssFeedRoute:
        type: Simple
        routes:
          - routePath: '/rss.xml'
            _controller: 'Vendor\你的扩展名\Controller\ArticleController::feed'
            _pageUid: 456
    
  3. 清除TYPO3缓存后,访问domain.com/rss.xml即可直接获取XML内容。

额外注意:

确保扩展已在ext_localconf.php中注册控制器:

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
    '你的扩展名称',
    '你的插件名称',
    [
        \Vendor\你的扩展名\Controller\ArticleController::class => 'feed',
    ],
    // 若需实时更新,将feed设为非缓存动作
    [
        \Vendor\你的扩展名\Controller\ArticleController::class => 'feed',
    ]
);

内容的提问来源于stack exchange,提问作者180690

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 00:48:11