how to: use Tx_Extbase_Domain_Repository_FrontendUserRepository in typo3 v4.5

StackOverflow https://stackoverflow.com/questions/19861883

  •  29-07-2022
  •  | 
  •  

Pergunta

I am trying to read the username of a front end user whose uid is known. I tried this in my controller's showAction method:

$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; 

but when that code runs I get:

Oops, an error occured! "Tx_Extbase_Domain_Repository_FrontendUserRepository " is not a valid cache entry identifier.

It turns out that $repository is empty, so how do I get fe_user data?

I am using typo3 v4.5 with extbase.

Thanks

Update to show complete answer. This is the code (it goes in my CouponController) that worked (plus the typoscript mentioned):

 /** 
     * @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() );

}
Foi útil?

Solução

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 >

Outras dicas

Set the source storage pid where the repository fetches the data from:

/** @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
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top