“Could not analyse class: maybe not loaded or no a

2019-08-04 16:07发布

I created (my first) extension with one viewhelper.

Oops, an error occurred!

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

In use (with news):

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

Directory tree of extension:

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条回答
爷、活的狠高调
2楼-- · 2019-08-04 16:26

You need to use camel case in the view helper invocation:

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

Furthermore you may need to define an autoload definition in your ext_emconf.php if you're using TYPO3 >=7.6 (reinstall the extension after doing so):

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

For more information see: http://insight.helhum.io/post/130876393595/how-to-configure-class-loading-for-extensions-in

查看更多
登录 后发表回答