Apress / the-typo3-guidebook

Source code for 'The TYPO3 Guidebook' by Felicity Brand, Heather McNamee, and Jeffrey A. McGuire
https://www.apress.com/9781484265246
Other
8 stars 5 forks source link

Exception: Controller does not exist, p244 #4

Open gerathjen opened 3 years ago

gerathjen commented 3 years ago

After working through the 4th step in the 9th chapter on page 244, Typo3 throws the following exception when the subpage Next readings is called:

(1/2) #1278450972 TYPO3\CMS\Extbase\Reflection\Exception\UnknownClassException
Class Promotionevents\Controller\PromotionTourWebsite\PromotionEvents\Controller\EventsControllerController does not exist. Reflection failed.

Exception-Controller-does-not-exist

The file EventsController.php is in the folder public/typo3conf/ext/promotionevents/Classes/Controller. I used the source code available in Github under https://github.com/Apress/the-typo3-guidebook/tree/main/Ch09/Step_4/promotionevents.

Note: I haven't only cleared the Typo3 and Composer cache, but also run the command ddev composer dumpautoload. The file composer.json contains the following lines:

  "autoload": {
    "psr-4": {
      "PromotionTourWebsite\\PromotionEvents\\": "public/typo3conf/ext/promotionevents/Classes"
    }
  },
PhilippKuhlmay commented 3 years ago

@gerathjen Is this your whole composer.json file? This is mine:

{
    "name": "typo3/cms-base-distribution",
    "description" : "TYPO3 CMS Base Distribution",
    "license": "GPL-2.0-or-later",
    "config": {
        "platform": {
            "php": "7.4.1"
        },
        "sort-packages": true
    },
    "require": {
        "helhum/typo3-console": "^6.4.0",
        [LIST OF TYPO3 PACKAGES]
    },
    "autoload": {
        "psr-4": {
            "PromotionTourWebsite\\PromotionEvents\\": "public/typo3conf/ext/promotionevents/Classes"
        }
    },
    "scripts":{
        "typo3-cms-scripts": [
            "typo3cms install:generatepackagestates",
            "typo3cms install:fixfolderstructure"
        ],
        "post-autoload-dump": [
            "@typo3-cms-scripts"
        ]
    }
}

The autoload section should be nested inside an additional { }

gerathjen commented 3 years ago

@PhilippKuhlmay Thank you for the quickly answer. My mistake was to use the autoload line in the file packages/promotionevents/composer.json. When I use them in the file composer.json from the Docroot directory, the Typo3 exception is no longer output.

However, I would prefer to have the statement to load the classes for PromotionEvents in the composer.json file in the extension directory.