TYPO3 扩展开发:Composer 自动加载无法识别自定义类

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

我目前正在开发 TYPO3 扩展,并面临 Composer 自动加载器无法识别我的自定义类的问题。我的目标是使用 Extbase 获取数据并将其传递给 Fluid 模板。

我的扩展作曲家看起来像这样

{
  "name": "toumeh/mywebsite",
  "description": "my Website",
  "type": "typo3-cms-extension",
  "license": "GPL-2.0-or-later",
  "authors": [
    {
      "name": "toumeh",
      "email": "[email protected]"
    }
  ],

  "require": {
    "typo3/cms-fluid-styled-content": "^12.4.0",
    "ext-pdo": "*"
  },
  "autoload": {
    "psr-4": {
      "MyWebsite\\Classes\\": "Classes/"
    }
  },
  "extra": {
    "typo3/cms": {
      "extension-key": "mywebsite"
    }
  }
}

将类添加到 ext_localconf.php,这样我就可以在我的打字脚本设置中使用插件

use MyWebsite\Classes\Controller\MyWebsiteController;
use MyWebsite\Classes\Domain\PageRepository;
use TYPO3\CMS\Extbase\Utility\ExtensionUtility;

ExtensionUtility::configurePlugin(
    MyWebsiteController::EXTENSION_NAME,
    MyWebsiteController::PLUGIN_NAME,
    [
        MyWebsiteController::CONTROLLER_NAME => PageRepository::PAGES
    ]
);

出现以下错误

找不到类“MyWebsite\Classes\Controller\MyWebsiteController”

在 /var/www/t3coredev/packages/mywebsite/ext_localconf.php 第 11 行 使用 MyWebsite\Classes\Domain\PageRepository; 使用 TYPO3\CMS\Extbase\Utility\ExtensionUtility;

扩展实用程序::configurePlugin( 我的网站控制器::EXTENSION_NAME, 我的网站控制器::PLUGIN_NAME, [ MyWebsiteController::CONTROLLER_NAME => PageRepository::PAGES ]

  1. 正在运行 compose dump-autoload 但它不起作用
  2. exbase 扩展位于我的根作曲家“typo3/cms-extbase”内部:“^12.4.0”
  3. 我很确定这不是权限问题。

这是我的项目结构中的一个 snapchat enter image description here

正在使用typo3 Composer版本12.4.8

有人可以帮助我理解为什么我的类没有被 Composer 的自动加载器识别以及我如何解决这个问题

php composer-php typo3 typo3-extensions
1个回答
0
投票

MyWebsite\Classes\Controller\MyWebsiteController
- 我认为这条路是你的问题。 TYPO3 使用一些命名约定,我很确定您需要从该路径中删除类部分。

use MyWebsite\Controller\MyWebsiteController; 

尝试一下!

© www.soinside.com 2019 - 2024. All rights reserved.