0

I'm currently writing my own extension based on extbase 1.4.6 on typo3 4.6.18. I have a single plugin that is configured with a flexform utilizing switchableControllerActions to determine which action to execute. Both actions do basically the same but call a different set of data (of the same type) from the db. This is a simplified version of my controlloer:

class Tx_MyExtension_Controller_MyCurrentController extends Tx_Extbase_MVC_Controller_ActionController {

    private $this->extKey = 'my_extension';
    protected $myRepository;

    public function initializeAction() {
        $this->myRepository = t3lib_div::makeInstance('Tx_MyExtension_Domain_Repository_MyObjectRepository');
    }

    public function listFutureAction() {
        t3lib_div::devLog('[listFutureAction] loading objects from DB', $this->extKey);
        $myObjects = $this->myRepository->findFuture();

        if ($myObjects->count() > 0) {
            // do something
        } else {
            t3lib_div::devLog("[listFutureAction] no result from repository data!", $this->extKey);
        }

        $this->view->assign(/* not important */);
    }

    public function listPastAction() {
        t3lib_div::devLog('[listPastAction] loading objects from DB', $this->extKey);
        $myObjects = $this->myRepository->findPast();

        if ($myObjects->count() > 0) {
            // do something
        } else {
            t3lib_div::devLog("[listPastAction] no result from repository data!", $this->extKey);
        }

        $this->view->assign(/* not important */);
    }
}

I get the data by implementing the following repository:

class Tx_MyExtension_Domain_Repository_MyObjectRepository extends Tx_Extbase_Persistence_Repository {

    /**
     * Finds all of my objects that are supposed happen in the future.
     * @return Tx_Extbase_Persistence_QueryResultInterface
     */
    public function findFuture() {
        $query = $this->createQuery();
        $query->matching($query->greaterThanOrEqual('dateTime', new DateTime()));
        return $query->execute();
    }

    /**
     * Gets all of my objects in the past that are intended to be shown.
     * @return Tx_Extbase_Persistence_QueryResultInterface
     */
    public function findPast() {
        $query = $this->createQuery();
        $query->matching(
            $query->logicalAnd(
                $query->lessThan('dateTime', new DateTime()),
                $query->equals('visibleWhenPast', true)
            )
        );

        return $query->execute();
    }
}

Up until here it works, as long I have only one plugin on the page. I can switch the actions and get the different results I expect. When I put the same plugin 2 times on the page the plugin I put on the page first will work fine, but the second one won't get any results. Looking at the dev log I always get "no result from repository data!" from the second plugin call.

Can anyone explain why this is happening?

gsnerf
  • 573
  • 1
  • 4
  • 15
  • Please don't use `t3lib_div::makeInstance` to create an instance of a repository, use `$this->objectManager->get('classname')` instead or better - use injection. Have you tried to create a fresh repository in each method? – Merec Jun 20 '13 at 16:10
  • Thx for the objectManager tip, up until now I followed the advice in extbase books like the one from O'Reilly (http://shop.oreilly.com/product/9783897219656.do) or Mittwald (https://www.mittwald.de/extbase-dokumentation/) which admittedly are a bit old. Unfortunatelly using the objectManager does not change a thing. I actally started out creating the repository in each method but extracted this to initializeAction to debug the problem at hand. How does injection work (and does this work with extbase 1.4.6?) – gsnerf Jun 20 '13 at 21:32
  • http://docs.typo3.org/flow/TYPO3FlowDocumentation/TheDefinitiveGuide/PartIII/ObjectManagement.html#dependency-injection Pretty much applies to extbase too (as extbase is the backport of Flow). – pgampe Jun 21 '13 at 23:35

0 Answers0