首页 > 解决方案 > 扩展中的多个控制器

问题描述

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

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

我知道我可以使用页面 id 并基于它调用函数,但我试图避免它并寻找更好的解决方案。

标签: typo3typo3-extensionstypo3-9.x

解决方案


当然这是可能的。您需要在这里使用 FlexForms,它基本上是 tt_content 记录中基于 XML 的字段。因此,您可以直接配置您的插件您的内容记录。通常用于设置记录限制、排序等。但也用于设置任何允许的控制器->动作组合,其中第一个是默认值。看看他们如何使用它的一些众所周知的扩展。下面是 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>

如前所述,您可以定义任何控制器/操作组合,例如 MyProduct->index 或 MyCustomer->list 等。

为了使用 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');

推荐阅读