gpt4 book ai didi

php - 单个数据库查询 TYPO3 Fluid 扩展

转载 作者:行者123 更新时间:2023-11-29 15:43:51 25 4
gpt4 key购买 nike

我正在使用 TYPO3 和 Fluid 以更加熟悉它。我需要进行单独的数据库查询,并将输出保存为数组。在官方 TYPO3 文档页面上,它非常简单地介绍了如何在我的 Controller 中执行单独的数据库查询。

/**
* Returns all objects of this repository.
*
* @return QueryResultInterface|array
* @api
*/
public function findAll()
{
return $this->createQuery()->execute();
}

作为尝试,我将这个公共(public)函数放在我的扩展 Controller 中,但是如何使用 foreach 循环在前端输出数据?

我想输出usermanager扩展中的数据。

编辑:使用 TYPO3 v. 9

最佳答案

您必须将其分配给流体 View 的变量:

$this->view->assign('varName', $data);

然后您可以通过 Fluid For-ViewHelper 迭代“varName”: https://docs.typo3.org/other/typo3/view-helper-reference/9.5/en-us/typo3fluid/fluid/latest/For.html

编辑:上面的代码必须位于存储库内。存储库是 Controller 和数据库之间的“桥梁”。要调用它,您只需将存储库注入(inject) Controller ( https://wiki.typo3.org/Dependency_Injection )并调用 findAll 函数:

public function customAction(): void
{
$this->view->assign(
'objects',
$this->repositoryVarName->findAll()
);
}

这可能对您有帮助:https://docs.typo3.org/m/typo3/book-extbasefluid/master/en-us/4-FirstExtension/3-create-the-domain-model.html
https://docs.typo3.org/m/typo3/book-extbasefluid/master/en-us/6-Persistence/2a-creating-the-repositories.html

关于php - 单个数据库查询 TYPO3 Fluid 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57290500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com