【问题标题】:Extbase / TYPO3 - How To generate a queryExtbase / TYPO3 - 如何生成查询
【发布时间】:2015-05-10 19:09:55
【问题描述】:

我的extbase模型“show”,有很多记录“production”。生产可以是“结束的”或“当前的”。它在生产模型中声明。

在“节目”-节目中,我想列出当前作品和已结束的作品。目前只能使用<f:for each="{productions}"...> 和条件列出它。

但我想这样做<f:for each="{currentProductions}"...<f:for each="{endedProductions}"...

所以我为我的作品库写了一个查询:

public function aktuelleProduktionen(Musicalplanet\MpDatenbank\Domain\Model\Produktionen $produktionen) {
    $query = $this->createQuery();
    $query->matching(
        $query->logicalOr(
            $query->equals('openend', '1'),
            $query->equals('abgelaufen', '0')
            )
        );
    return $query->execute();
}

但现在我真的不知道如何让它工作。 对我来说,不清楚在哪里添加它,按照我需要的方式使用它。

【问题讨论】:

  • 您能否更具体地说明“在哪里添加和使用它”?你尝试了什么?
  • (题外话)尽量避免使用非英语的命名方法——你会避免像getProduktFromKorb这样的语言怪物;)我们也会更容易帮助你

标签: typo3 extbase


【解决方案1】:

首先,我认为您的查询方法应该更像这样才能获得节目的制作:

public function aktuelleProduktionen(Musicalplanet\MpDatenbank\Domain\Model\Show $show) {
  $query = $this->createQuery();
  $query->matching(
      $query->logicalAnd(
          $query->equals('show', $show->getUid()),
          $query->logicalOr(
              $query->equals('openend', '1'),
              $query->equals('abgelaufen', '0')
          )
      )
  );
  return $query->execute();
}

我猜,当你有一个 show-Model 时,你也有一个 Show-Controller。在其中,您应该注入您的 ProductionRepository:

/**
 * programRepository
 *
 * @var \Musicalplanet\MpDatenbank\Domain\Model\ProduktionenRepository
 * @inject
 */
protected $produktionenRepository;

现在您可以使用自定义查询方法从该存储库中获取当前作品。在您的 showAction() 中执行此操作。

public function showAction(Musicalplanet\MpDatenbank\Domain\Model\Show $show) {
  $currentProductions = $this->produktionenRepository->aktuelleProduktionen($show);
  $this->view->assign('currentProductions', $currentProductions);
}

或多或少,这应该有效。希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多