“Could not analyse class: maybe not loaded or no autoloader?”

邮差的信 提交于 2019-12-24 07:06:49

问题


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:


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



来源:https://stackoverflow.com/questions/41239226/could-not-analyse-class-maybe-not-loaded-or-no-autoloader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!