从控制器中的FlexForms获取TYPO3插件设置

时间:2013-10-31 08:47:12

标签: php typo3 typoscript extbase

我有一个使用FlexForm MyExtFlexForm的FE插件,用于设置某些配置,例如limit or SourcePage etc..

在我的控制器操作list中,我使用$this->settings获取这些设置。到目前为止工作正常。

现在,我对行动update进行AJAX调用,我需要使用之前通过FlexForm为此页面上的FE插件设置的相同设置。 $this->settings does not show anything

我检查了$GLOBALS['TSFE']->tmpl->setup['plugin']['MyExt.']['settings.'],此处没有显示FlexForm中定义的任何设置。

如何解决此问题?

编辑:

我的示例Flexform如下所示:

<sheets>
        <sDEF>
            <ROOT>
                <TCEforms>
                    <sheetTitle>View Settings</sheetTitle>
                </TCEforms>
                <type>array</type>
                <el>
                    <switchableControllerActions>
                        <TCEforms>
                            <label>Select</label>
                            <config>
                                <type>select</type>
                                <items>
                                    <numIndex index="0">
                                        <numIndex index="0">MyFunction</numIndex>
                                        <numIndex index="1">MyExt->list</numIndex>
                                    </numIndex>
                                </items>
                            </config>
                        </TCEforms>
                    </switchableControllerActions>

                    <settings.flexform.limit>
                        <TCEforms>
                            <label>Number of items to be displayed</label>
                            <config>
                                <type>input</type>
                                <size>10</size>
                            </config>
                        </TCEforms>
                    </settings.flexform.limit>
                </el>
            </ROOT>
        </sDEF>
    </sheets>

然后我对我的控制器操作进行AJAX调用并打印此$this->settings,不显示任何设置。

2 个答案:

答案 0 :(得分:1)

我刚刚遇到了一个解决方案:https://forum.typo3.org/index.php/t/194022/eigener-extbase-controller-keine-flexform-werte

我包含了这样的插件:

AJAX_PAGE = PAGE
AJAX_PAGE {
    typeNum = 2

    10 < tt_content.list.20.myPlugin

    config {
        disableAllHeaderCode = 1
        xhtml_cleaning = 0
        admPanel = 0
        debug = 0
        no_cache = 1
    }
}

为了正确加载设置,应该是:

AJAX_PAGE = PAGE
AJAX_PAGE {
    typeNum = 2

    10 < styles.content.get
    10 {
        select.where = colpos = 0
        select.andWhere = list_type='myPlugin'
    }

    config {
        disableAllHeaderCode = 1
        xhtml_cleaning = 0
        admPanel = 0
        debug = 0
        no_cache = 1
    }
}

答案 1 :(得分:0)

最简单的解决方案是在FlexForm中使用正确的命名字段,即如果您的字段将以settings.为前缀,则会在$this->settings数组中显示:

<settings.myField>
    <TCEforms>
        <label>My very special setting</label>
        <config>
            <type>input</type>
        </config>
    </TCEforms>
</settings.myField>

控制器:

$mySetting = $this->settings['myField'];

另一方面,如果您计划将TS设置与FlexForm设置合并,则可以在其前添加其他一些词语,如:<settings.flexform.myField>,然后访问它:

$fromTypoScript = $this->settings['myField'];
$fromFlexform   = $this->settings['flexform']['myField'];

// or...
$myMergedSetting = (!$this->settings['flexform']['myField'])
                   ? $this->settings['myField']
                   : $this->settings['flexform']['myField'];