php TYPO3 Extbase - 按照逗号逗号列表的顺序获取产品

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php TYPO3 Extbase - 按照逗号逗号列表的顺序获取产品相关的知识,希望对你有一定的参考价值。

<?php

use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;

/**
 * The repository for ExampleRepository
 */
class ExampleRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
  
  /**
     * Find all results by a list of uids and order by this uid list
     *
     * @param String $uidList List of uids
     * @return array
     */
	public function findAllByCommaIdString(String $uidList) {
        $uids = GeneralUtility::intExplode(',', $uidList, true);
        if ($uidList === '' || count($uids) === 0) {
            return [];
        }

        $dataMapper = GeneralUtility::makeInstance(DataMapper::class);

        /** @var QueryBuilder $queryBuilder */
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
            ->getQueryBuilderForTable('tx_example_domain_model_example');

        $rows = $queryBuilder
            ->select('*')
            ->from('tx_example_domain_model_example')
            ->where($queryBuilder->expr()->in('uid', $uids))
            ->add(
                'orderBy',
                'FIELD(tx_example_domain_model_example.uid,' . implode(',', $uids) . ')'
            )
            ->execute()
            ->fetchAll();

        return $dataMapper->map(\FooBar\Example\Domain\Model\Example::class, $rows);
    }
}

以上是关于php TYPO3 Extbase - 按照逗号逗号列表的顺序获取产品的主要内容,如果未能解决你的问题,请参考以下文章

TYPO3 Extbase - 在单个视图中更改浏览器页面标题

如何使用 extbase 在 TYPO3 CMS 6.0 上引导插件?

Typo3 7.6 extbase 存储库匹配仅影响非本地化记录

如何在typo3 V10的extbase控制器中重定向到404页面

Extbase - 从查询中获取创建的 sql

TYPO3 前端用户存储库