扩展中的多个控制器

时间:2019-05-13 12:18:00

标签: typo3 typo3-extensions typo3-9.x

实际上是否可以编写带有多个控制器的扩展程序,这些扩展程序将在所有站点上自动运行?我想要的是一个扩展,它将在打开站点A时调用控制器A,在打开站点B时调用控制器B,等等。

我在这里https://docs.typo3.org/typo3cms/extensions/news/看到,使用 FlexForms switchableControllerActions 可以使用多个控制器。关键是,当我将插件添加到站点时,我必须指定哪个控制器适用于该站点。我希望直接在扩展程序中进行配置,而不是从typo3后端进行配置。

我知道我可以使用页面ID并基于页面ID调用函数,但是我正尝试避免使用它并寻求更好的解决方案。

1 个答案:

答案 0 :(得分:0)

当然可以。您需要在此处使用FlexForms,它基本上是tt_content记录中基于XML的字段。因此,您可以直接配置您的内容记录插件。通常用于设置记录,排序等的限制。还用于设置任何允许的controller-> action组合,其中第一个是默认组合。只是看看一些众所周知的扩展如何使用它。 这是FlexForm相关部分的一个抽象摘要:

                    <switchableControllerActions>
                    <TCEforms>
                        <label>LLL:EXT:ra_registration/Resources/Private/Language/locallang_be.xml:flexforms_general.mode</label>
                        <config>
                            <type>select</type>
                            <items>
                                <numIndex index="0">
                                    <numIndex index="0">LLL:EXT:ra_registration/Resources/Private/Language/locallang_be.xml:flexforms_general.mode.registration_index</numIndex>
                                    <numIndex index="1">Registration->index;Registration->register;User->new;User->create;User->confirm;User->index;User->remind</numIndex>
                                </numIndex>
                                <numIndex index="1">
                                    <numIndex index="0">LLL:EXT:ra_registration/Resources/Private/Language/locallang_be.xml:flexforms_general.mode.registration_reminder</numIndex>
                                    <numIndex index="1">User->index;User->remind;User->remindConfirm</numIndex>
                                </numIndex>
                            </items>
                        </config>
                    </TCEforms>
                </switchableControllerActions>

如前所述,您可以定义任何控制器/动作组合,例如 我的产品->索引 要么 MyCustomer->列表 等

要使用FlexForm,您需要在ext_tables.php中注册它

$TCA['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue('myextenion_pi1', 'FILE:EXT:' . $_EXTKEY . '/Configuration/FlexForms/setup.xml');
相关问题