我目前正在typo3 4.6.18 上基于extbase 1.4.6 编写自己的扩展。我有一个插件,它配置了一个弹性表单,利用 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 次相同的插件时,我第一次放置在页面上的插件可以正常工作,但第二个插件不会得到任何结果。查看开发日志我总是得到“没有来自存储库数据的结果!” 从第二个插件调用。
谁能解释为什么会这样?