Typo3 8.7.x / Extbase:如何获取页面的sys_category

时间:2018-08-28 12:03:40

标签: php typo3 php-7 extbase typo3-8.x

有人可以告诉我如何在扩展程序的控制器处获取页面的sys_category吗?

public function listAction()
{
//get the sys categories of (a) page
???

谢谢

1 个答案:

答案 0 :(得分:0)

现在,我用QueryBuilder编写了一个解决方案。也许可以帮助其他人:

在我的扩展程序->控制器中

/**
 * pagesRepository
 *
 * @var \TYPO3\CMS\Frontend\Page\PageRepository
 * @inject
 */
protected $pageRepository = null;

在我的扩展程序->控制器-> someaction中:

    foreach ($GLOBALS['TSFE']->rootLine as $page) {

        $pageObject = $this->pageRepository->getPage($page['uid']);

        if ($pageObject['categories']) {
            $queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)->getQueryBuilderForTable('sys_category');
            $query = $queryBuilder->select('sys_category.uid', 'sys_category.title')->from('sys_category');
            $query->join(
                'sys_category',
                'sys_category_record_mm',
                'mm',
                $queryBuilder->expr()->andX(
                    $queryBuilder->expr()->eq('mm.uid_local', $queryBuilder->quoteIdentifier('sys_category.uid')),
                    $queryBuilder->expr()->in('mm.uid_foreign', $page['uid']),
                    $queryBuilder->expr()->eq('mm.tablenames', $queryBuilder->quote('pages')),
                    $queryBuilder->expr()->eq('mm.fieldname', $queryBuilder->quote('categories'))
                )
            );

            $result = $query->execute()->fetchAll();

            break;
        }
    }