在自己的扩展中使用TYPO3的核心FrontendUserGroupRepository

时间:2016-03-16 15:11:47

标签: typo3 extbase

我尝试以下列方式为TYPO3的前端用户组实例化核心存储库:

    $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
    $feGroupRepo = $objectManager->create('\\TYPO3\\CMS\\Extbase\\Domain\\Repository\\FrontendUserGroupRepository');
    var_dump($feGroupRepo->findAll()->toArray());

结果我得到了sql错误:

#1247602160: Table 'tablename.tx_extbase_domain_model_frontendusergroup' doesn't exist

为什么这个repo使用了错误的表?如何以正确的方式配置它以使用系统表'fe_groups'?

3 个答案:

答案 0 :(得分:1)

您使用的TYPO3版本是什么? Normaly应该有extbase包含的typoscript,告诉自己不要查看与命名空间和类名匹配的表,而不是fe_groups。它应该是这样的:

config.tx_extbase {
    persistence{
        classes {
            TYPO3\CMS\Extbase\Domain\Model\FrontendUserGroup {
                mapping {
                    tableName = fe_groups
                    columns {
                        lockToDomain.mapOnProperty = lockToDomain
                    }
                }
            }
        }
    }
}

如果由于某种原因不存在,请将其自行包含在TypoScript中。

请不要使用dprecated方法$objectManager->create(),但请始终使用$objectManager->get()

答案 1 :(得分:0)

尝试做丹尼尔所说的:

  • ->create(替换为->get(
  • 检查config.tx_extbase.persistence.classes.TYPO3\CMS\Extbase\Domain\Model\FrontendUserGroup.mapping.tableName的TypoScript对象浏览器设置部分,应该等于fe_groups。它应该是pressent,否则添加它 - 但它应该在那里!

稍微多一点,删除TYPO3前面的双反斜杠。这可能是TYPO3无法检测到正确的TypoScript路径的原因:

$feGroupRepo = $objectManager->get('TYPO3\\CMS\\Extbase\\Domain\\Repository\\FrontendUserGroupRepository');

之后,清除整个缓存(最终删除typo3temp文件夹中的所有文件,有时需要删除它。)

答案 2 :(得分:0)

而不是$objectManager->create('etcetera'),请尝试$objectManager->get('etcetera')。如果您想要更长时间的讨论和更多想法,请查看已接受的答案here

相关问题