“无法分析类:可能没有加载或没有自动加载器?”

时间:2016-12-20 09:46:49

标签: typo3 fluid typo3-6.2.x

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

  

糟糕,发生错误!

     

无法分析类:我的\ Mlv \ ViewHelpers \ Format \ ReplacenewlinesViewHelper可能没有加载或没有自动加载器?

使用中(有新闻):

{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;
    }
}

1 个答案:

答案 0 :(得分:3)

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

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

此外,如果您使用TYPO3&gt; = 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