1

我正在尝试读取已知 uid 的前端用户的用户名。我在控制器的 showAction 方法中尝试了这个:

$objectManger = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
// get repository
$repository = $objectManger->get('Tx_Extbase_Domain_Repository_FrontendUserRepository ');
$newObject = $repository->findByUid($coupon->getCreator()); //this is the uid of whoever was loggin in
print_r($newObject);
echo $newObject->getUsername(); die; 

但是当该代码运行时,我得到:

糟糕,发生错误!“Tx_Extbase_Domain_Repository_FrontendUserRepository”不是有效的缓存条目标识符。

原来$repository 是空的,那么如何获取fe_user 数据呢?

我正在使用带有 extbase 的typo3 v4.5。

谢谢

更新以显示完整答案。这是有效的代码(它在我的 CouponController 中)(加上提到的打字稿):

 /** 
     * @var Tx_Extbase_Domain_Repository_FrontendUserRepository 
     */ 
    protected $userRepository; 

      /**  
       * Inject the user repository
       * @param Tx_Extbase_Domain_Repository_FrontendUserRepository $userRepository 
       * @return void */ 
      public function injectFrontendUserRepository(Tx_Extbase_Domain_Repository_FrontendUserRepository $userRepository) { 
          $this->userRepository = $userRepository;             
      }


public function showAction(Tx_Coupons_Domain_Model_Coupon $coupon) {

           $userRepository = $this->objectManager->get("Tx_Extbase_Domain_Repository_FrontendUserRepository");

            $newObject =  $userRepository->findByUid($coupon->getCreator());

            $this->view->assign('coupon', $coupon);
            $this->view->assign('creatorname', $newObject->getUsername() );

}
4

2 回答 2

2

If you are using extbase yourself you dont have to call makeInstance for your objectManager, it's already there ($this->objectManager).

anyway, you should inject this repository (see my answer here: TYPO3 - Call another repository)

Clear the Cache after the Injection.

You maybe have to disable the recordtype extbase sets for its FrontendUser:

config.tx_extbase.persistence.classes.Tx_Extbase_Domain_Model_FrontendUser.mapping.recordType >
于 2013-11-08T17:30:05.340 回答
1

设置存储库从中获取数据的源存储 pid:

/** @var Tx_Extbase_Domain_Repository_FrontendUserRepository $repos */
$repos = $this->objectManager->get("Tx_Extbase_Domain_Repository_FrontendUserRepository");

$querySettings = $repos->createQuery()->getQuerySettings();
$querySettings->setStoragePageIds(array(123, 567));
$repos->setDefaultQuerySettings($querySettings);

$user = $repos->findByUid(56); // Queries for user 56 in storages 123 and 567
于 2013-11-08T16:14:20.043 回答