1

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() );

}
The Newbie Qs
  • 483
  • 8
  • 22

2 Answers2

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 >
Community
  • 1
  • 1
Daniel
  • 6,916
  • 2
  • 36
  • 47
1

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
Merec
  • 2,751
  • 1
  • 14
  • 21
  • That looks interesting, did you declare the vars $repos and $this->objectmanager differently than I did in my code frag? outside of the method? looks like you made objectManager a member var, but not $repos? and the numbers for the array, where did you get them? – The Newbie Qs Nov 08 '13 at 16:54
  • i got it working with injection and without the querysettings. i'll update my q with code. – The Newbie Qs Nov 08 '13 at 20:38
  • You can inject object manager like this.. http://lbrmedia.net/codebase/Eintrag/typo3-624-repository-instanzieren/ – Vishal Tanna Oct 30 '15 at 07:33