简体   繁体   English

使用f:form viewhelper将Fluid-Template中的数组提交给Controller

[英]Submit array from Fluid-Template to Controller with f:form viewhelper

I am currently writing an Extbase Extension with a backend module. 我目前正在编写带有后端模块的Extbase扩展。 I have assigned an array to the template of my backend module. 我已经为后端模块的模板分配了一个数组。 Now I am trying to submit that array back to my crontroller action "pageGenerator" with inputs of the form in the template. 现在,我尝试使用模板中表单的输入将该数组提交回我的crontroller操作“ pageGenerator”。 Here is the code from my controller and template: 这是我的控制器和模板中的代码:

Controller: 控制器:

public function listAction()
{
    $array = [
        '1' => '',
        '2' => '',
        '3' => ''
    ];
    $this->view->assign('array', $array);
    $this->view->setTemplatePathAndFilename('EXT:bm_test/Resources/Private/Templates/template.html');

}
public function pageGeneratorAction(array $array=null){}

Fluid-Template: 流体模板:

 <div align="center">
  <f:form method="post" controller="DomainModel" action="pageGenerator" 
     name="array" object="{array}" >
    <input type="text" name="array[1]">
    <input type="text" name="array[2]">
    <input type="text" name="array[3]"> 
    <f:form.submit value="Submit" />
</f:form>
 </div>

The problem is that the array is null no matter what I type into the textfields.When i remove the "=null" from the pageGenerator action i get the following Error: 问题是无论我在文本字段中键入什么内容,数组都为null。当我从pageGenerator动作中删除“ = null”时,出现以下错误:

Too few arguments to function Bmt\BmTest\Controller\DomainModelController::pageGeneratorAction(), 0 passed and exactly 1 expected

So it seems like that the array isn't submitted. 因此,似乎未提交数组。 Does anyone know what am I doing wrong here? 有人知道我在这里做错什么吗? Thanks in advance for your help. 在此先感谢您的帮助。

have you tried to insert the assign variable after setTemplatePathAndFilename ? 您是否尝试在setTemplatePathAndFilename之后插入assign变量? Becouse in typo3 if the template haven't the same name of the Action you need first inizialize them and after return the view with assigned variable example 因为在typo3中,如果模板名称与操作名称不同,则需要先将其初始化,然后返回带有指定变量示例的视图

$this->view->setTemplatePathAndFilename('EXT:bm_test/Resources/Private/Templates/template.html');
$this->view->assign('array', $array);
return $this->view->render();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM