尝试使用TYPO3 12 ActionController时出现ServiceNotFoundException

问题描述 投票:0回答:2

当尝试注册我的 DummyController 以将其用作 Typo3 插件时,我收到以下错误:

ServiceNotFoundException: You have requested a non-existent service "MyVendorName\Typo3StarterSitepackage\Controller\DummyController"

我尝试按照文档所述执行所有操作,并且还做了一些研究,但巴德无法解决问题。这是我的代码:

我的控制器:

<?php

namespace MyVendorName\Typo3StarterSitepackage\Controller;

use Psr\Http\Message\ResponseInterface;

class DummyController extends ActionController
{
    public function dummyListAction(): ResponseInterface
    {
        return $this->htmlResponse();
    }
}

我的DummyRepository.php:

<?php

namespace MyVendorName\Typo3StarterSitepackage\Domain\Repository;

use TYPO3\CMS\Extbase\Persistence\QueryInterface;

class DummyRepository extends Repository
{
    // this already has some default functions, like findAll(), inherited from the Repository class.
}

我的 Services.yaml 文件:

services:
  # general settings
  _defaults:
    autowire: true
    autoconfigure: true
    public: false

  MyVendorName\Typo3StarterSitepackage\:
    resource: '../Classes/*'

我的ext_localconf.php:

<?php

use MyVendorName\Typo3StarterSitepackage\Controller\DummyController;
use TYPO3\CMS\Extbase\Utility\ExtensionUtility;

defined('TYPO3') or die('Access denied.');
/***************
 * Add default RTE configuration
 */
// $GLOBALS['TYPO3_CONF_VARS']['RTE']['Presets']['typo3_starter_sitepackage'] = 'EXT:typo3_starter_sitepackage/Configuration/RTE/Default.yaml';

/***************
 * PageTS
 */
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:typo3_starter_sitepackage/Configuration/TsConfig/Page/All.tsconfig">');

ExtensionUtility::configurePlugin(
    'typo3_starter_sitepackage',
    'DummyList',
    [DummyController::class => 'dummyList'],
);

使用此代码,我可以通过 Typo3 后端选择插件,但随后会抛出 ServiceNotFoundException。我知道控制器现在没有返回任何内容,但我认为这不是这个问题的原因。

我正在 Windows 上使用 XAMPP 和 PHP 8.2、Typo3 12.4.10。

php typo3 autoload
2个回答
0
投票

与这些案例相关的偶然错误是:

  • 在 Services.yaml 中重新检查类和命名空间的大小写、文件和相应的composer.json 自动加载命名空间(旧模式的+ext_emconf.php 自动加载部分)。
  • 检查你是否真的没有排除控制器

并尝试重建缓存

vendor/bin/typo3 cache:flush
vendor/bin/typo3 cache:warump

0
投票

我终于能够解决这个问题了。我的安装有两个主要问题,老实说,我想部分归咎于 TYPO3 的怪癖和文档不足。无论如何,这是我修复它的方法:

  • 虽然TYPO3网站声明typo3 12兼容PHP 8.2,但我遇到了一些问题,主要是一些奇怪的学说错误,最终切换到PHP 8.1。
  • composer.json 文件带有预定义的“typo3-cms-scripts”,其中调用了
    typo3cms install:fixfolderstructure
    。这对我来说从来没有用过,因为这条路径对于typo3 12来说似乎是错误的。相反,我设置了
    typo3 cache:flush
    typo3 cache:warmup

之后,我删除了composer.lock文件和供应商文件夹,并重新安装了composer包(这可能没有必要)。自动加载后转储脚本现在清除了typo3缓存,运行时没有错误,并且ServiceNotFoundException消失了。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.