1

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.

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.

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:

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.

Zlatan Omerović
  • 3,863
  • 4
  • 39
  • 67

1 Answers1

2

You'll have to inject the Repository for FrontenduserGroups from Extbase

 /**
 * @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. Here is a cheatsheet that might help you 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
  • the storagePid needs to be set to the UID of the folder that contains the usergroups in the backend
cephei_vv
  • 220
  • 3
  • 14
  • Could I do the injection with a method instead of using `@inject`? I had problems with that so I try to avoid it... – Zlatan Omerović Oct 25 '17 at 15:40
  • You can inject the class by writing a methos injectFrontendUserGroupRepository() and provide the namespace for FrontendUserGroupRepository as parameter. – cephei_vv Oct 25 '17 at 15:44
  • Sadly, it doesn't work. It injects the repository, but findAll doesn't return anything, but I have data in that table. – Zlatan Omerović Oct 25 '17 at 15:54
  • That sounds like the "storagePid" is not set. the storagePid needs to be set to the ID of the folder that contains your usergroups in backend. https://stackoverflow.com/questions/17244616/set-typo3-extbase-storagepageids-storagepid-to-current – cephei_vv Oct 25 '17 at 16:03
  • I've set it up, but still does not work... I've set it like `storagePid = 28` where my groups are defined. – Zlatan Omerović Oct 25 '17 at 22:58