【问题标题】:Multiple controllers in an extension扩展中的多个控制器
【发布时间】:2019-05-13 12:18:00
【问题描述】:

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

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

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

【问题讨论】:

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


    【解决方案1】:

    当然可以。您需要在这里使用 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>
    

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

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

    【讨论】:

      猜你喜欢
      • 2012-03-18
      • 1970-01-01
      • 2015-01-09
      • 2018-02-19
      • 1970-01-01
      • 2011-08-19
      • 2012-01-05
      • 2015-01-22
      • 1970-01-01
      相关资源
      最近更新 更多