can I add properties to a typo3 extbase domain model object?

Posted by The Newbie Qs on Stack Overflow See other posts from Stack Overflow or by The Newbie Qs
Published on 2013-11-08T21:49:52Z Indexed on 2013/11/08 21:53 UTC
Read the original article Hit count: 182

Filed under:
|
|
|
|

I want to store a username in a coupon object, each coupon object already has the uid of the user who created it. I can loop over the coupon objects and read the associated usernames from fe_users but how then will I save those usernames into the coupons so when they are passed to the template the usernames can be read like so coupon.username, or in some other easy way so each username will appear on the page with the right coupon as they are all printed out in a table?

If I was doing basic php instead of typo3 i would just define a query but what is the typo3 v4.5 way?

My code so far - which dies on the line where I try to assign the new property --creatorname -- to the $coup object.

public function listAction() {
        $coupons = $this->couponRepository->findAll();
                // @var Tx_Extbase_Domain_Repository_FrontendUserRepository $userRepository */
                $userRepository = $this->objectManager->get("Tx_Extbase_Domain_Repository_FrontendUserRepository");
                foreach ($coupons as $coup) {
                    echo '<br />test '.$coup->getCreator(); 
                    echo '<br />count = '.$userRepository->countAll().'<br />';
                    $newObject =  $userRepository->findByUid( intval($coup->getCreator()));
                    //var_dump($newObject);

                    var_dump($coup);
                    echo '<br />getUsername '.$newObject->getUsername() ; 
                    $coup['creatorname'] = $newObject->getUsername();
                     echo '<br />creatorname '.$coup['creatorname'] ; 
                }
        $this->view->assign('coupons', $coupons);
    }

© Stack Overflow or respective owner

Related posts about php

Related posts about object