我用一个 viewhelper 创建了(我的第一个)扩展。
糟糕,出现错误!
无法分析类:My\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;
}
}
您需要在视图助手调用中使用驼峰式大小写:
{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 http://insight.helhum.io/post/130876393595/how-to-configure-class-loading-for-extensions-in
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)