【问题标题】:TYPO3: How to use storage pid from pagetree in backend module?TYPO3:如何在后端模块中使用 pagetree 中的存储 pid?
【发布时间】:2013-05-08 01:43:37
【问题描述】:

我使用 Extension Builder 创建了一个扩展,并在 web 部分下包含了一个后端模块。在生成的代码中,存储 pid 有两个常量:一个用于插件,一个用于模块。

现在我喜欢我的模块使用来自页面树中选定页面或文件夹的存储 pid,就像页面、列表或模板模块一样。如何在后端模块中使用 pagetree 中的存储 pid 而不是使用常量?

【问题讨论】:

    标签: typo3 extbase


    【解决方案1】:

    要从后端模块中的页面树中获取所选页面,一种方法是简单地获取 id 参数,最好是在初始化程序中。

    由于 extbase 从您的模块(或前端插件)设置中读取存储 pid,您只需覆盖 storagePid 部分,因此您不必为每个查询设置 pid/否则在您的存储库中。

    以下应该有效。但是,我在 CommandController 中使用它,而不是在后端使用的控制器中。我无需更改任何内容,因为存储库会自动将记录范围限定为所选页面。

    class Tx_MyExt_Controller_BackendController extends Tx_Extbase_MVC_Controller_ActionController {
    
        /**
         * @var Tx_Extbase_Configuration_ConfigurationManagerInterface
         * @inject 
         */
        protected $configurationManager;
    
        /**
         * @var int Current page
         */
        protected $pageId;
    
    
        /**
         * Action initializer
         *
         * @return void
         */
        protected function initializeAction()
        {
            $this->pageId = (int)t3lib_div::_GP('id');
    
            $frameworkConfiguration = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
            $persistenceConfiguration = array('persistence' => array('storagePid' => $this->pageId));
            $this->configurationManager->setConfiguration(array_merge($frameworkConfiguration, $persistenceConfiguration));
        }
    
    }
    

    【讨论】:

    • 是的。但是存储库对象仍然使用存储 pid TypoScript 配置中的值。如何更新存储库对象的存储 pid?
    • 您必须手动修改它。当我再次访问我的代码时,将在星期五更新我的答案。
    • 谢谢。我不得不重新编写示例以计算 Typo3 6 中的新命名空间,但它确实有效。
    • pduersteler,谢谢。你能告诉我这是否是为后端和前端引导 $pageId 的正确方法吗? if($GLOBALS['TSFE'] === NULL){ $this->pageId = (int) \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id'); }else{ $this->pageId = $GLOBALS['TSFE']->id; }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-23
    • 2020-04-27
    相关资源
    最近更新 更多