您的代码中有一些常见错误,其中大部分已在此处提及,但请允许我总结一下。
扩展键/名称
首先,很多人将扩展名与扩展键混淆了。您的扩展的目录名称是您的扩展键,在本例中为snippet_highlight_syntax。 扩展密钥在 TYPO3 中被用作扩展的唯一标识符。对于 Extbase,确实出现了一个名为 extension name 的新约定,以满足 PSR2 coding convention 的要求,并且主要用于 Extbase 上下文。 扩展名是您的扩展键的大写驼峰式版本。
ExtbaseFluidBook: CodingGuidelines - 这是一个旧的出价但仍然有效
UpperCamelCase 中的扩展名。例如,如果 extension-key 是 blog_example,那么这部分类名就是 BlogExample。
分机键:snippet_highlight_syntax
扩展名:SnippetHighlightSyntax
注意 TYPO3/Extbase 框架要求什么,键或名称 - 这会对您有很大帮助。
插件名称
您还声明了一个名为feshs 的插件。根据 \TYPO3\CMS\Extbase\Utility\ExtensionUtility::(configure|register)Plugin() 两种方法的 DocBlock 文档,与扩展名一样,它应该采用大写驼峰式格式,如 Feshs。它没有很好的记录,我认为它对您的应用程序没有任何负面影响,但现在您知道并且可以通过更正它来证明您的应用程序的未来。
/**
* ...
*
* @param string $extensionName The extension name (in UpperCamelCase) or the extension key (in lower_underscore)
* @param string $pluginName must be a unique id for your plugin in UpperCamelCase (the string length of the extension key added to the length of the plugin name should be less than 32!)
* @param array $controllerActions is an array of allowed combinations of controller and action stored in an array (controller name as key and a comma separated list of action names as value, the first controller and its first action is chosen as default)
* @param array $nonCacheableControllerActions is an optional array of controller name and action names which should not be cached (array as defined in $controllerActions)
* @param string $pluginType either \TYPO3\CMS\Extbase\Utility\ExtensionUtility::PLUGIN_TYPE_PLUGIN (default) or \TYPO3\CMS\Extbase\Utility\ExtensionUtility::PLUGIN_TYPE_CONTENT_ELEMENT
* @throws \InvalidArgumentException
*/
public static function configurePlugin($extensionName, $pluginName, array $controllerActions, array $nonCacheableControllerActions = [], $pluginType = self::PLUGIN_TYPE_PLUGIN)
插件签名
与您的扩展名一起,它将形成一个名为snippethighlightsyntax_feshs 的插件签名。此签名是存储在tt_content 数据库表中的值,为list_type 或ctype,具体取决于插件配置。
插件签名在 TypoScript 和 GET/POST 参数中进一步使用,前缀为 tx_。在你的情况下tx_snippethighlightsyntax_feshs。
流体和 Extbase 表格
在您的表单 sn-p 中,您声明了一个带有 property 标记的元素 <f:form:textfield />。 property 标签仅与 <f:form /> 元素上的 object 和 objectName 标签一起使用,用于将值绑定到此对象的属性(自动填充、验证结果等)。
见\TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::initializeArguments。
对象属性的名称。如果与<f:form object="..."> 结合使用,“name”和“value”属性将被忽略。
在您的情况下,您应该正确地使用 name 而不是 property。
您更新后的表单应如下所示:
<f:form id="snippetSearchForm"
action="search"
controller="Snippets"
extensionName="SnippetHighlightSyntax"
pluginName="Feshs"
method="POST"
pageType="5513">
<f:form.textfield class="form-control" name="searchWords"/>
<f:form.submit id="searchBtn" value="Search"/>
</f:form>
控制器参数
您应该将您的参数声明为控制器参数。
/**
* @param string $searchWords
*/
public function searchAction(string $searchWords = null)
{
if (is_string($searchWords)) {
// TODO: Do something here...
}
}
注意我是如何给参数一个默认值的。这应该会抑制您收到的错误 Required argument "searchWords" is not set for...。
这是一篇很长的文章。希望它对您或其他人有所帮助。
快乐编码