在第一次没有获得结果之后,多次调用相同的存储库

时间:2013-06-20 15:23:01

标签: typo3 extbase

我目前在typo3 4.6.18上基于extbase 1.4.6编写自己的扩展。 我有一个配置了flexform的插件,利用switchableControllerActions来确定要执行的操作。这两个操作基本相同,但从db调用不同的数据集(相同类型)。这是我的控制器的简化版本:

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

我通过实现以下存储库来获取数据:

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

直到这里它才有效,只要我在页面上只有一个插件。我可以切换动作并获得我期望的不同结果。当我在页面上放置相同的插件2次时,我首先在页面上放置的插件将正常工作,但第二个插件将不会得到任何结果。查看开发日志,我总是得到“存储库数据没有结果!”来自第二个插件电话。

任何人都可以解释为什么会这样吗?

0 个答案:

没有答案