"Could not analyse class: maybe not loaded or no autoloader?"

"Could not analyse class: maybe not loaded or no autoloader?"

我用一个 viewhelper 创建了(我的第一个)扩展。

Oops, an error occurred!

Could not analyse class:My\Mlv\ViewHelpers\Format\ReplacenewlinesViewHelper maybe not loaded or no autoloader?

正在使用(有新闻):

{namespace m=My\Mlv\ViewHelpers}
{newsItem.bodytext -> m:format.replacenewlines()}

扩展的目录树:

typo3conf/ext/mlv
  ext_emconf.php (copied from another ext)
  /Classes
    /ViewHelpers
      /Format
        ReplaceNewLinesViewHelper.php

ReplaceNewLinesViewHelper.php:

<?php
namespace My\Mlv\ViewHelpers\Format;

/**
 * Replaces newlines in plain text with <br> tags.
 *
 * @author johndoe33
 * @package Mlv
 * @subpackage ViewHelpers\Format
 */
class ReplaceNewLinesViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {

    /**
     * Replaces newlines in plain text with <br> tags.
     *
     * @param string $content
     * @return string
     */
    public function render($content = NULL) {
        if (NULL === $content) {
            $content = $this->renderChildren();
        }
        $content = str_replace( "\n", '<br>', $content );
        return $content;
    }
}

您需要在视图助手调用中使用驼峰式大小写:

{newsItem.bodytext -> m:format.replaceNewLines()}

此外,如果您使用的是 TYPO3 >=7.6(执行此操作后重新安装扩展),您可能需要在 ext_emconf.php 中定义一个自动加载定义:

'autoload' => array(
  'psr-4' => array('My\Mlv\' => 'Classes')
)

有关详细信息,请参阅:http://insight.helhum.io/post/130876393595/how-to-configure-class-loading-for-extensions-in