Search code examples
phptypo3autoload

ServiceNotFoundException when trying to use TYPO3 12 ActionController


When Trying to register my DummyController to use it as a Typo3 Plugin, I get the following error: ServiceNotFoundException: You have requested a non-existent service "MyVendorName\Typo3StarterSitepackage\Controller\DummyController"

I tried to do everything like the documentation states, and also did some research, bud was unable to resolve the issue. Here is my code:

My controller:

<?php

namespace MyVendorName\Typo3StarterSitepackage\Controller;

use Psr\Http\Message\ResponseInterface;

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

My 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.
}

My Services.yaml file:

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

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

My 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'],
);

With this code I am able to select the Plugin through the Typo3 Backend, but then the ServiceNotFoundException is thrown. I am aware that the Controller doesn't return anything right now, but I think that's not the cause of this issue.

I am working on Windows using XAMPP with PHP 8.2, Typo3 12.4.10.


Solution

  • I was able to fix the issue. There were two main problems with my installation. Here is how I fixed it:

    • I had some issues with PHP 8.2, mainly some doctrine errors, and eventually switched to PHP 8.1.
    • The composer.json file that was created after initializing my project with the command composer create-project typo3/cms-base-distribution example-project-directory "^12" came with predefined "typo3-cms-scripts", where typo3cms install:fixfolderstructure was called. This didn't work for me. Instead I set typo3 cache:flush and typo3 cache:warmup.

    After that, I deleted my composer.lock file and my vendor folder and freshly installed the composer packages (this might not have been necessary). The post autoload dump script, that now clears the typo3 caches, ran without errors and the ServiceNotFoundException went away.