我有一个扩展,我需要在其中获取所有前端用户。我试过这个:
/**
* @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:
'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
}
}
谢谢你。