Typo3 6.1 Extbase - 选择所有fe用户

时间:2014-01-22 14:20:53

标签: typo3 frontend extbase selectall

我有一个扩展,我需要获得所有前端用户。 我试过这个:

    /**
     * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository $feUserRepository
     */
    $feUserRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( 'TYPO3\\CMS\\Extbase\\Domain\\Repository\\FrontendUserRepository' );
    $allUsers = $feUserRepository->findAll();
    $user = $feUserRepository->findByUid( 1 );

findByUid(1)有效,但findAll()返回一个空对象。 我在这里做错了什么?

更新

这是关于新闻扩展。我在tx_xxnews_domain_model_news和fe_users之间有一个mm关系,所以我可以跟踪哪些用户访问了哪些新闻。

TCA for News:

'columns' => array(
        ...

        'fe_users' => array(
            'exclude' => 0,
            'label' => 'LLL:EXT:xx_news/Resources/Private/Language/locallang_db.xlf:tx_xxnews_domain_model_news.fe_users',
            'config' => array(
                'type' => 'select',
                'foreign_table' => 'fe_users',
                'MM' => 'tx_xxnews_news_feuser_mm',
                'size' => 10,
                'autoSizeMax' => 30,
                'maxitems' => 9999,
                'multiple' => 0,
            ),
        ),
        ...
),

我必须向那些没有访问过新闻的用户单独显示,所以我还有2个列显示来自用户定义函数的内容:

'reading_users' => array (
    'exclude' => 0,
    'label' => 'LLL:EXT:xx_news/Resources/Private/Language/locallang_db.xlf:tx_xxnews_domain_model_news.user_info',
    'config' => array (
        'type' => 'user',
        'size' => '30',
        'userFunc' => 'EXT:xx_news/Classes/TCA/class.tx_xxnews_tca.php:tx_examples_tca->readersInfo',
        'parameters' => array(
            'read' => TRUE
        )
    )
),
'not_reading_users' => array (
    'exclude' => 0,
    'label' => 'LLL:EXT:xx_news/Resources/Private/Language/locallang_db.xlf:tx_xxnews_domain_model_news.user_info',
    'config' => array (
        'type' => 'user',
        'size' => '30',
        'userFunc' => 'EXT:xx_news/Classes/TCA/class.tx_xxnews_tca.php:tx_examples_tca->readersInfo',
        'parameters' => array(
            'read' => FALSE
        )
    )
),

class.tx_xxnews_tca.php:

class tx_examples_tca {

    /**
     * @var \Vendor\XxNews\Domain\Repository\NewsRepository $newsRepository
     */
    protected $newsRepository;

    /**
     * Class constructor
     */
    public function __construct() {
        $this->newsRepository = new \Vendor\XxNews\Domain\Repository\NewsRepository;
    }

    public function readersInfo($params) {

        /**
         * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository $feUserRepository
         */
        $feUserRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( 'TYPO3\\CMS\\Extbase\\Domain\\Repository\\FrontendUserRepository' );
        $allUsers = $feUserRepository->findAll();
        $user = $feUserRepository->findByUid( 1 );

        var_dump( $allUsers ); //EMPTY
        var_dump( $user );     //OK
    }
}

谢谢。

1 个答案:

答案 0 :(得分:4)

问题在于,当TYPO3引入Extbase时,会集成前端用户的“记录类型”。 (这只是作为一个例子完成的,将在6.2 BTW中删除。)

您必须将每个前端用户的记录类型设置为您的扩展的记录类型(它在您的扩展名的ext_tables.php中定义),或者您可以删除(清除)记录类型的必要性

config.tx_extbase.persistence.classes.Vendor/MyExtension/Domain/Model/User.mapping.recordType =

编辑: 顺便说一句,您应该注入存储库而不是使用makeInstance:

/**
 * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
 * @inject
 */
protected $feUserRepository;