[英]Extbase / TYPO3 - How To generate a query
My extbase model "show", has got a lot of records "production". 我的extbase模型“ show”,已经有很多记录“ production”。 A Production can be "ended" or "current".
生产可以是“结束”或“当前”。 It's declared in the Model of productions.
在生产模型中声明。
In a "Show"-Show I want to list the current productions and the ended ones. 在“表演”中,我想列出当前的作品和结束的作品。 Currently it's only possible to list it with
<f:for each="{productions}"...>
and a condition. 当前,只能用
<f:for each="{productions}"...>
和一个条件列出它。
But I want to do it like in this way <f:for each="{currentProductions}"...
or <f:for each="{endedProductions}"...
但是我想以这种方式
<f:for each="{currentProductions}"...
或<f:for each="{endedProductions}"...
So I wrote a query for my repository of productions: 因此,我为自己的生产资料库写了一个查询:
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();
}
but now I really don't know how to make it working. 但是现在我真的不知道如何使它工作。 For me it's not clear where to add it, to use it like I need it.
对我来说,不清楚在哪里添加它,以及像我需要的那样使用它。
First of all, I think your query method should be more like this to get the productions of a show: 首先,我认为您的查询方法应更像这样以获取演出的作品:
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();
}
I guess, when you have a show-Model, you have a Show-Controller, too. 我想,当您有一个展示模型时,您也会有一个展示控制器。 Inside that, you should inject your ProductionRepository:
在其中,您应该注入ProductionRepository:
/**
* programRepository
*
* @var \Musicalplanet\MpDatenbank\Domain\Model\ProduktionenRepository
* @inject
*/
protected $produktionenRepository;
Now you can use your custom query method to get your current productions out of that Repository. 现在,您可以使用自定义查询方法从该存储库中获取当前的作品。 Do that in your showAction().
在showAction()中执行此操作。
public function showAction(Musicalplanet\MpDatenbank\Domain\Model\Show $show) {
$currentProductions = $this->produktionenRepository->aktuelleProduktionen($show);
$this->view->assign('currentProductions', $currentProductions);
}
More or less, this should work. 或多或少,这应该工作。 Hope that helps.
希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.