TYPO3教程扩展,控制器不存在 [英] TYPO3 tutorial extension, controller does not exist
问题描述
我正在尝试开始使用TYPO3扩展,并且正在关注此教程,以了解基础知识.
I'm trying to get started with TYPO3 extensions and was following this tutorial to get to see the basics.
在后端,一切正常,但是在前端,我得到一个错误:
In the backend everything works fine, but on the front end I get an error:
糟糕,发生错误!编码:20170209104827c3b58d58- {"exception":消息为'Class的exception'ReflectionException' Tx_Inventory_Controller_InventoryController不存在'
Oops, an error occurred! Code: 20170209104827c3b58d58 - {"exception":"exception 'ReflectionException' with message 'Class Tx_Inventory_Controller_InventoryController does not exist'
我的文件与本教程中的文件完全相同.我不知道是什么原因造成的.我以为我对名称空间犯了一些愚蠢的错误,但是它们似乎都是正确的.
My files are exactly the same as in the tutorial. I have no idea what is causing this. I assume I made some dumb mistake with namespaces, but they seem to be all correct.
可以在下面找到控制器类,该类位于 typo3conf/ext/inventory/Classes/Controller/
The controller class can be found below and is located in typo3conf/ext/inventory/Classes/Controller/
<?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);
}
}
?>
推荐答案
在已安装TYPO3 V9(此处为9.4)的作曲家中开发新扩展时,必须将自动加载部分添加到中央根composer.json.在此处(德语)找到它.遵循提到的操作指南中的步骤会导致核心异常:
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.
只要未通过composer安装扩展名,例如因为它是新开发的,composer便不会在扩展目录中找到相应的composer.json
文件.因此,TYPO3在新的扩展Classes
目录中找不到任何类.要解决此问题,必须将自动加载配置添加到根composer.json
.只需将以下几行放入安装基本目录中的composer.json
中:
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.
这篇关于TYPO3教程扩展,控制器不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!