简体   繁体   English

如何在TYPO3中获取fe_groups数组?

[英]How to get an array of fe_groups in TYPO3?

I'm pretty new to TYPO3 and many things are confusing at the moment, especially how the data modeling and data fetching actually works if you're relying on ExtBase. 我对TYPO3还是很陌生,目前有很多事情令人困惑,尤其是如果您依赖于ExtBase,则数据建模和数据获取实际上是如何工作的。

Thing I want to achive is to get an array of records from the fe_groups table and pass it into my Fluid view and render those items in f:form.select input field. 我要实现的是从fe_groups表中获取记录数组,并将其传递到我的Fluid视图中,并在f:form.select输入字段中呈现这些项目。

So far, I've tried nothing since I have no idea from where and how to start it. 到目前为止,我什么也没做,因为我不知道从哪里开始以及如何开始。

Other thing I've did successfully is to pass a hard coded array of object items into my view, and rendered them successfully, like this: 我成功完成的另一件事是将对象项目的硬编码数组传递到我的视图中,并成功呈现了它们,如下所示:

<f:form.select
    class="form-control"
    property="taskTypes"
    options="{taskTypes}"
    optionValueField="name"
    optionLabelField="value"
    id="taskTypes" />

This is the method in my Controller which fills the taskTypes array: 这是控制器中填充taskTypes数组的方法:

private function getTaskTypes() {
    $task_type_names = [
        ' - Task Types - ',
        'New client',
        'Maintenance',
    ];
    $task_types = [];

    foreach($task_type_names as $i => $task_type_name) {
        $task_type = new \stdClass();
        $task_type->key = $i;
        $task_type->value = $task_type_name;

        $task_types[] = $task_type;
    }

    return $task_types;
}

And then a simple view assignment in controller's action: 然后在控制器的动作中进行简单的视图分配:

$this->view->assign('taskTypes', $this->getTaskTypes());

And this works like a charm! 这就像一个魅力!

But I'm clueless how to do something similar with dynamic content fetched from the database tables. 但是我不知道如何对从数据库表中获取的动态内容执行类似的操作。

So, basically, I just need a way to pass items from fe_groups table to my view and render them. 所以,基本上,我只需要一种方法就可以将项目从fe_groups表传递到我的视图并进行渲染。

You'll have to inject the Repository for FrontenduserGroups from Extbase 您必须从Extbase注入FrontenduserGroups的存储库

 /**
 * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserGroupRepository
 * @inject
 */
protected $feUserGroupRepository;

in your method you can then use this Repository to get the data from the database 然后,您可以使用此存储库从数据库中获取数据

$feUserGroup = $this->feUserGroupRepository->findAll();
$userByUid = $this->feUserGroupRepository->findByUid(12);

The repository also provides more ->findBy* methods. 该存储库还提供更多->findBy*方法。 Here is a cheatsheet that might help you http://lbrmedia.net/codebase/Eintrag/extbase-query-methods/ 这是一份可以帮助您的备忘单http://lbrmedia.net/codebase/Eintrag/extbase-query-methods/

Note: 注意:

  • the @inject in the doc comment is actually parsed by Extbase and loads the class that is refered in @var @inject在文档注释实际上是由Extbase解析,并加载在所指向的类@var
  • the storagePid needs to be set to the UID of the folder that contains the usergroups in the backend 必须将storagePid设置为包含后端用户组的文件夹的UID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM