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.
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:
@inject
in the doc comment is actually parsed by Extbase and loads the class that is refered in @var
storagePid
needs to be set to the UID of the folder that contains the usergroups in the backend