TYPO3 tutorial extension, controller does not exist

时间秒杀一切 提交于 2019-12-05 10:42:10

When developing a new extension in a composer installed TYPO3 V9 (here: 9.4) the autoload part has to be added to the central root composer.json. Found it here (German). Following the steps in the OPs mentioned tutorial leads to a core exception:

Core: Exception handler (WEB): Uncaught TYPO3 Exception: #1278450972:
  Class MyVendor\StoreInventory\Controller\StoreInventoryController does not exist.
  Reflection failed.

As long as the extension is not installed via composer, e.g because it's newly developed, composer does not find the appropriate composer.json file in the extensions directory. Hence TYPO3 does not find any classes in the new extensions Classes directory. To resolve the issue the autoload configuration has to be added to the root composer.json. Just put the following lines into composer.json within the installations base directory:

{
    "repositories": [
        { "type": "composer", "url": "https://composer.typo3.org/" }
    ],
    ...
    "autoload": {
        "psr-4": {
            "MyVendor\\StoreInventory\\": "public/typo3conf/ext/store_inventory/Classes/"
        }
    }
}

Then regenerate the autoload configuration:

composer dumpautoload

You possibly have to clear the cache as well in the backend.

Remove backslashes - try with

<?php
namespace MyVendor\Inventory\Controller;

use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use MyVendor\Inventory\Domain\Model\Repository\ProductRepository;

class InventoryController extends ActionController {

    public function listAction() {
            $productRepository = GeneralUtility::makeInstance(ProductRepository::class)
            $products = $productRepository->findAll();
            $this->view->assign('products', $products);
    }
}

Ensure you add Vendorname to extension key, when you register your plugin, see ext_tables.php and write 'MyVendor.'.$_EXTKEY instead of $_EXTKEY like

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
    'MyVendor.'.$_EXTKEY,
    'List',
    'The Inventory List'
);
Pierre Fru

It looks like your class is not autoloaded. If you don't use composer to make your autoload, take a look in your typo3conf/autoload/autoload_classmap.php file.

You should find an entry corresponding to your file. You will see if you have a path error.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!